#45008 [Opn->Fbk]: get_object_vars bug ?

From: Date: Fri, 16 May 2008 21:43:05 +0000
Subject: #45008 [Opn->Fbk]: get_object_vars bug ?
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-125061@lists.php.net to get a copy of this message
ID: 45008 Updated by: jani@php.net Reported By: bruno dot caillaud at cndp dot fr -Status: Open +Status: Feedback Bug Type: *General Issues Operating System: Windows XP PHP Version: 5.2.6 New Comment: And what's the bug here anyway? As it clearly says in the manual page for get_object_vars(): "Gets the public properties of the given object". Private is not public and as the method is in context of the "Base" class, why would it include private properties of extending class? (Disclaimer: This is how _I_ understand this :) You get expected result if you define getProperties() method in the Child class tool.. Previous Comments: ------------------------------------------------------------------------ [2008-05-16 21:30:29] jani@php.net Just a note about bug #42814: "No feedback" is not same as "Closed" in which case there would be an entry in the NEWS file about a fixed bug.. ------------------------------------------------------------------------ [2008-05-15 14:41:48] bruno dot caillaud at cndp dot fr Description: ------------ I read the Bug #42814 which is supposed to be closed, however, I have reproduced this bug in the last version 5.2.6 this is a sample code : <?php class Base { private $basePrivateProperty; protected $baseprotectedProperty; function getProperties () { return get_object_vars ( $this ); } } class Child extends Base { private $childPrivateProperty; protected $childprotectedProperty; } echo "Base :<br/>\n"; $father = new Base(); var_dump($father->getProperties()); echo "<br/>Child :<br/>\n"; $children = new Child(); var_dump($children->getProperties()); ?> Running this sample code Result on different versions of php 5: PHP version 5.2.0 to 5.2.3 : Base : array(2) { ["basePrivateProperty"]=> NULL ["baseprotectedProperty"]=> NULL } Child : array(3) { ["childPrivateProperty"]=> NULL ["childprotectedProperty"]=> NULL ["baseprotectedProperty"]=> NULL } PHP version 5.2.4 to 5.2.6: Base : array(2) { ["basePrivateProperty"]=> NULL ["baseprotectedProperty"]=> NULL } Child : array(3) { ["childprotectedProperty"]=> NULL ["basePrivateProperty"]=> NULL ["baseprotectedProperty"]=> NULL } I think the good behaviour is the one returned by versions 5.2.0 to 5.2.3. in 5.2.4 version and up, the child can access to his parent's private property but not to his own private property Reproduce code: --------------- <?php class Base { private $basePrivateProperty; protected $baseprotectedProperty; function getProperties () { return get_object_vars ( $this ); } } class Child extends Base { private $childPrivateProperty; protected $childprotectedProperty; } echo "Base :<br/>\n"; $father = new Base(); var_dump($father->getProperties()); echo "<br/>Child :<br/>\n"; $children = new Child(); var_dump($children->getProperties()); ?> Expected result: ---------------- Base : array(2) { ["basePrivateProperty"]=> NULL ["baseprotectedProperty"]=> NULL } Child : array(3) { ["childPrivateProperty"]=> NULL ["childprotectedProperty"]=> NULL ["baseprotectedProperty"]=> NULL } Actual result: -------------- Base : array(2) { ["basePrivateProperty"]=> NULL ["baseprotectedProperty"]=> NULL } Child : array(3) { ["childprotectedProperty"]=> NULL ["basePrivateProperty"]=> NULL ["baseprotectedProperty"]=> NULL } ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=45008&edit=1

« previous php.bugs (#125061) next »