From f193f6c844b271e47b7699931121e6a7e9af2565 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Wed, 23 Jan 2008 22:34:20 +0000 Subject: [PATCH] Added __set_state() example (same in var_export()) and __callStatic() in list. git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@251213 c90b9560-bf6c-de11-be94-00142212c4b1 --- language/oop5/magic.xml | 52 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/language/oop5/magic.xml b/language/oop5/magic.xml index 3ddea35f9d..da2fd17284 100644 --- a/language/oop5/magic.xml +++ b/language/oop5/magic.xml @@ -1,5 +1,5 @@ - + Magic Methods @@ -8,16 +8,17 @@ __destruct (see Constructors and Destructors), __call, + __callStatic, __get, __set, __isset, - __unset + __unset (see Overloading), __sleep, __wakeup, __toString, __set_state and - __clone + __clone are magical in PHP classes. You cannot have functions with these names in any of your classes unless you want the magic functionality associated @@ -160,6 +161,51 @@ Hello The only parameter of this method is an array containing exported properties in the form array('property' => value, ...). + + Using <literal>__set_state</literal> (since PHP 5.1.0) + +var1 = $an_array['var1']; + $obj->var2 = $an_array['var2']; + return $obj; + } +} + +$a = new A; +$a->var1 = 5; +$a->var2 = 'foo'; + +eval('$b = ' . var_export($a, true) . ';'); // $b = A::__set_state(array( + // 'var1' => 5, + // 'var2' => 'foo', + // )); +var_dump($b); + +?> +]]> + + &example.outputs; + + + int(5) + ["var2"]=> + string(3) "foo" +} +]]> + +