Skip to Content
Mastering PHP 7
book

Mastering PHP 7

by Branko Ajzele
June 2017
Intermediate to advanced
536 pages
9h 49m
English
Packt Publishing
Content preview from Mastering PHP 7

Using __set_state()

The __set_state() magic method is triggered (not really) for classes exported by the var_export() function. The method accepts a single array type parameter and returns an object, as per the following synopsis:

static object __set_state(array $properties)

The var_export() function outputs or returns a parsable string representation of a given variable. It is somewhat similar to the var_dump() function, except that the returned representation is a valid PHP

<?phpclass User{  public $name = 'John';  public $age = 34;  private $salary = 4200.00;  protected $identifier = 'ABC';}$user = new User();var_export($user); // outputs string "User::__set_state..."var_export($user, true); // returns string "User::__set_state..."

This ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning PHP 7

Learning PHP 7

Antonio L Zapata (GBP)
Upgrading to PHP 5

Upgrading to PHP 5

Adam Trachtenberg

Publisher Resources

ISBN: 9781785882814Supplemental Content