Edit report at http://bugs.php.net/bug.php?id=51479&edit=1

 ID:               51479
 User updated by:  ian at ianhobson dot co dot uk
 Reported by:      ian at ianhobson dot co dot uk
 Summary:          property_exists now wrong
 Status:           Bogus
 Type:             Bug
 Package:          Class/Object related
 Operating System: Windows
 PHP Version:      5.3.2

 New Comment:

A miss-feature that is correctly implmented and documented is still -
erm - a miss-feature.



What is the use of being told a property exists if you can neither read
from it nor write to is without triggering a fatal error.


Previous Comments:
------------------------------------------------------------------------
[2010-04-22 02:03:17] fel...@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



------------------------------------------------------------------------
[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

Reply via email to