What is the purpose of the transient keyword

The transient keyword in PHP is used to indicate that a property of a class should not be serialized when the object is serialized. This is useful for properties that are derived from other sources or properties that should not be saved, such as database connections or file handles.
transient, PHP, serialization, class properties, object-oriented programming
<?php class Example { public $name; public $age; transient public $connection; // This will not be serialized } $obj = new Example(); $obj->name = 'John'; $obj->age = 30; $obj->connection = new mysqli('localhost', 'user', 'password', 'database'); $serialized = serialize($obj); var_dump($serialized); // 'connection' property will not be included ?>

transient PHP serialization class properties object-oriented programming