#34893 [Asn->Csd]: PHP5.1 overloading, Cannot access private property

From: Date: Thu, 20 Oct 2005 09:48:17 +0000
Subject: #34893 [Asn->Csd]: PHP5.1 overloading, Cannot access private property
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-86799@lists.php.net to get a copy of this message
ID: 34893 Updated by: dmitry@php.net Reported By: kai at meder dot info -Status: Assigned +Status: Closed Bug Type: Scripting Engine problem Operating System: * PHP Version: 5.1.0RC1 Assigned To: helly New Comment: Fixed in CVS HEAD and PHP_5_1 Previous Comments: ------------------------------------------------------------------------ [2005-10-19 21:51:36] johannes@php.net Ilia, Tony, you're right with php5.0 but this has somewhen changed with php 5.1. Taking this short example: <?php class A { private $p; function __set($name, $value) { echo "in __set()\n"; $this->$name = $value; } } $a = new A(); $a->p = true; var_dump($a); ?> With PHP 5.0 this gives: Fatal error: Cannot access private property A::$p" With PHP 5.1 this gives in __set() object(A)#1 (1) { ["p:private"]=> bool(true) } Same goes for __get and __call and private/protected properties. The only problem /seems/ to be the combination of __get and __set as in the $a->p->t = "bar"; line of the original code. So something is broken - either it should work always or never. ------------------------------------------------------------------------ [2005-10-19 20:52:09] tony2001@php.net You were talking to one of the core developers, so I don't see a reason why you need another one to repeat the same. ------------------------------------------------------------------------ [2005-10-19 20:30:41] kai at meder dot info in php5.1 all betas and RC1 __get and __set are ALSO called when trying to access protected/private (invisible) properties. btw, the manual describes php5, not php5.1 which is in beta/rc-stadium ... so please forward this *bug* to the overload-developers! ------------------------------------------------------------------------ [2005-10-19 15:47:56] iliaa@php.net Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php Do you even read documentation? Getters and Setters can only be used to access properties that are not declared in the class. ------------------------------------------------------------------------ [2005-10-19 12:53:22] kai at meder dot info do you even read the bug-reports ? by trying to set a private-property __get/__set are triggered in php5.1 (yes, it already works!) but there is a serious problem if using __get AND __set together in a chain! ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/34893 -- Edit this bug report at http://bugs.php.net/?id=34893&edit=1

« previous php.bugs (#86799) next »