note 98785 added to function.get-object-vars
| From: | elminster2031 at hotmail dot com | Date: | Wed, 07 Jul 2010 19:30:23 +0000 |
| Subject: | note 98785 added to function.get-object-vars | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-170771@lists.php.net to get a copy of this message | ||
Also note that this is recursive. For example:
<?php
class Sarah{
private $Father;
private $Mother;
public function __construct(){
$this->Father = NULL; //I don't know Sarah's Father
$this->Mother = NULL; //I don't know Sarah's Mother
}
}
class John_Connor{
private $Father;
private $Mother;
public function __construct(){
$this->Father = $this; //John went back in time and fathered himself
$this->Mother = new Sarah(); //Sarah was his mom and his mate ewww
}
public function showParents(){
return get_object_vars($this);
}
}
$John = new John_Connor();
var_dump($John->showParents());
?>
You will see this outputs:
array(2) {
["Father"]=>
object(John_Connor)#1 (2) {
["Father":"John_Connor":private]=>
object(John_Connor)#1 (2) {
["Father":"John_Connor":private]=>
*RECURSION*
["Mother":"John_Connor":private]=>
object(Sarah)#2 (2) {
["Father":"Sarah":private]=>
NULL
["Mother":"Sarah":private]=>
NULL
}
}
["Mother":"John_Connor":private]=>
object(Sarah)#2 (2) {
["Father":"Sarah":private]=>
NULL
["Mother":"Sarah":private]=>
NULL
}
}
["Mother"]=>
object(Sarah)#2 (2) {
["Father":"Sarah":private]=>
NULL
["Mother":"Sarah":private]=>
NULL
}
}
----
Server IP: 64.71.164.2
Probable Submitter: 208.86.76.86
----
Manual Page -- http://www.php.net/manual/en/function.get-object-vars.php
Edit -- https://master.php.net/note/edit/98785
Del: integrated -- https://master.php.net/note/delete/98785/integrated
Del: useless -- https://master.php.net/note/delete/98785/useless
Del: bad code -- https://master.php.net/note/delete/98785/bad+code
Del: spam -- https://master.php.net/note/delete/98785/spam
Del: non-english -- https://master.php.net/note/delete/98785/non-english
Del: in docs -- https://master.php.net/note/delete/98785/in+docs
Del: other reasons-- https://master.php.net/note/delete/98785
Reject -- https://master.php.net/note/reject/98785
Search -- https://master.php.net/manage/user-notes.php