php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51479 property_exists now wrong
Submitted: 2010-04-05 15:26 UTC Modified: 2010-04-27 21:27 UTC
From: ian at ianhobson dot co dot uk Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.3.2 OS: Windows
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: ian at ianhobson dot co dot uk
New email:
PHP Version: OS:

 

 [2010-04-05 15:26 UTC] 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. 




Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-04-09 07:44 UTC] 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-22 02:03 UTC] felipe@php.net
-Status: Open +Status: Bogus
 [2010-04-22 02:03 UTC] felipe@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-27 21:27 UTC] ian at ianhobson dot co dot uk
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 17 23:01:32 2024 UTC