|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-03-31 06:56 UTC] ricardo at ish dot com dot br
Description: ------------ It seems to me that Bug #26010 is hauting us again. I can't get an useful result from get_object_vars($obj), unless its var are declared as public. Wasn't it supposed to be fixed on CSV since November, 10th, 2003? Thanks Ricardo PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 10:00:01 2025 UTC |
Here is the sample code: <?php class Foo { public $var1; private $var2; function __construct() { $this->var1 = 'A'; $this->var2 = 'B'; } public function dumpVars() { print_r(get_object_vars($this)); } } ?> <pre> <?php $myFoo = new Foo(); echo "My VARS:<br>\n"; $myFoo->dumpVars(); ?> </pre> Here is the behavior: ===================== My VARS: Array ( [var1] => A ) Here is the expected Behavior: ============================== My VARS: Array ( [var1] => A [var2] => B ) My opinion about it: ==================== Since the function get_object_vars is being called inside the class, it should have access to all PPP types, shouldn't it? (this example above is a dummy one, but it illustrates the problem quite well). Sorry about the delay of my reply.I've tried and isn't working yet (and I also get this error message - phpinfo() is ok and show PHP 5.0.1-dev): PHP has encountered an Access Violation at 00B4737A My VARS: Array ( [var1] => A ) HTTP/1.1 500 Server Error Server: Microsoft-IIS/5.1 Date: Tue, 20 Jul 2004 11:51:51 GMT Content-Type: text/html Content-Length: 44 -2147417842 (0x8001010e)I'll try to show a new example, to make my point: Source: ======= <?php class Foo { public $var1; private $var2; function __construct() { $this->var1 = 'A'; $this->var2 = 'B'; } public function dumpVars() { print_r(get_object_vars($this)); } } ?> <pre> <?php $myFoo = new Foo(); echo "My VARS:<br>\n"; $myFoo->dumpVars(); ?> </pre> ========== <pre> <?php print_r(get_object_vars($myFoo)); ?> </pre> Behavior: ========= My VARS: Array ( [var1] => A ) ========== Array ( [var1] => A ) Expected Behavior (IMHO): ========================= My VARS: Array ( [var1] => A [var2] => B ) ========== Array ( [var1] => A ) Explanation: ============ Note the difference between calling get_object_vars($this) inside a public method, inside the class (where all variables should be seen), and calling in the outside - get_object_vars($myFoo).