note 23105 added to function.get-object-vars
| From: | nick_eby@php.net | Date: | Tue, 09 Jul 2002 16:13:21 +0000 |
| Subject: | note 23105 added to function.get-object-vars | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-32803@lists.php.net to get a copy of this message | ||
Furthermore, variables not declared in the class but set on a given object, will be returned by
get_object_vars().
Example, ver. 4.2.1:
<?
class MyTest {
var $classVar1 = 'Class Var 1';
var $classVar2;
var $classVar3;
function MyTest()
{
$this->classVar2 = 'class var 2';
}
}
$test = new MyTest();
// This var isn't declared in the class
$test->newObjVar = 'foobar';
echo "<pre>";
print_r(get_object_vars($test));
echo "</pre>";
?>
The output is:
Array
(
[classVar1] => Class Var 1
[classVar2] => class var 2
[classVar3] =>
[newObjVar] => foobar
)
Prior to version 4.2, classVar3 would not be output as it was never assigned a value.
--
http://www.php.net/manual/en/function.get-object-vars.php
http://master.php.net/manage/user-notes.php?action=edit+23105
http://master.php.net/manage/user-notes.php?action=delete+23105
http://master.php.net/manage/user-notes.php?action=reject+23105