Bug #51479 [Com]: property_exists now wrong
[email protected] ("abca_b_cabcom at hotmail dot com") Fri, 9 Apr 2010 07:44:38 +0200 (CEST)
| Newsgroups | php.bugs |
|---|---|
| Message-ID | <[email protected]> |
Edit report at http://bugs.php.net/bug.php?id=51479&edit=1
ID: 51479
Comment by: abca_b_cabcom at hotmail dot com
Reported by: ian at ianhobson dot co dot uk
Summary: property_exists now wrong
Status: Open
Type: Bug
Package: Class/Object related
Operating System: Windows
PHP Version: 5.3.2
New Comment:
Hi ivan, i think you could use the reflection api to handle it
http://www.php.net/manual/en/reflectionproperty.isprivate.php
Previous Comments:
------------------------------------------------------------------------
[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