ID: 26325 User updated by: drm at melp dot nl Reported By: drm at melp dot nl Status: Open Bug Type: Feature/Change Request Operating System: Windows XP PHP Version: 5.0.0b2 (beta2) New Comment:
Here's a more explanatory piece of code: http://gerard.yoursite.nl/php.net/private-members.phps Previous Comments: ------------------------------------------------------------------------ [2003-11-19 17:49:24] drm at melp dot nl Description: ------------ Hi :) I read in the new features list of Zend Engine 2 that access modifiers like private/protected are introduced, but something really weird comes in mind when reading carefully. Private members are returned _empty_ wheing tried to be accessed from derived classes. "Intended behaviour", is said. OK, i can live with that. But even when i turned on notices with error_reporting, nothing is noticed? The case grows when looking at the following code sample. This could produce very weird bugs when writing PHP code (i hope you can see that ;)), so I would like to convince you all to at least implement a Notice when trying to access (non-defined) private (parent) members? It would do the coders not using E_ALL no harm :) Please consider this :) Reproduce code: --------------- error_reporting ( E_ALL ); class Test { private $member; function __construct () { $this->member = "Test constructor"; } function __toString () { return "Member contains: {$this->member}"; } function getMember () { return $this->member; } function setMember ( $m ) { $this->member = $m; } } class DeriveTest extends Test { function __construct () { parent::__construct (); } function __toString () { return "Member contains: {$this->member}, though getMember() says: " . $this->getMember() ."?"; } function setMember ( $m ) { $this->member = $m; } } $o = new DeriveTest (); echo $o, '<br>'; $o->setMember ( "a" ); echo $o, '<br>'; Expected result: ---------------- The expected result would be for me: Notice: undefined member ``DeriveTest::$member'' in ...\test.php on line 12 Member contains: , though getMember() says: Test constructor? Member contains: a, though getMember() says: Test constructor? or something of the sort Actual result: -------------- The actual result is: Member contains: , though getMember() says: Test constructor? Member contains: a, though getMember() says: Test constructor? ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=26325&edit=1