Bug #51479 [Opn->Bgs]: property_exists now wrong
| From: | felipe@php.net | Date: | Thu, 22 Apr 2010 00:03:17 +0000 |
| Subject: | Bug #51479 [Opn->Bgs]: property_exists now wrong | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-149766@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=51479&edit=1
ID: 51479
Updated by: felipe@php.net
Reported by: ian at ianhobson dot co dot uk
Summary: property_exists now wrong
-Status: Open
+Status: Bogus
Type: Bug
Package: Class/Object related
Operating System: Windows
PHP Version: 5.3.2
New Comment:
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
Previous Comments:
------------------------------------------------------------------------
[2010-04-09 07:44:38] abca_b_cabcom at hotmail dot com
Hi ivan, i think you could use the reflection api to handle it
http://www.php.net/manual/en/reflectionproperty.isprivate.php
------------------------------------------------------------------------
[2010-04-05 15:26:42] ian at ianhobson dot co dot uk
Description:
------------
Now that property_exists returns true for all private properties, there
is no way (I know) to test that a property is private before writing to
it and causing a fatal error.
The previous behaviour was wrong - private properties that are in scope
should return true - but the new code is worse.
See Bug #50810: property_exists does not work for private
I think property_exists should return true for writable properties...
which implies a scope...
if the user coded $this then the scope is the current scope.
If the use gives a class name, then the scope is that class.
I have not managed to re-code the routine below to work in 5.3.0 (let
alone both 5.3.? and 5.2.?).
Test script:
---------------
public function setField($fld, $value) {
// set the fld to the value
if (property_exists($this,$fld)) {
$this->$fld = $value; // handles public and protected fields
return;
}
$this->setMapped($fld,$value); // for private vars.
}
Create a class with the above function. Create a sub-class with a
private variable. Call it on the sub-class with fldname and value.
In 5.3.0 this crashes with a fatal error.
In 5.2.9 it calls setMapped.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=51479&edit=1