php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43847 Bug #34396 is not fixed - unset() un-declares a property
Submitted: 2008-01-15 02:24 UTC Modified: 2008-01-28 23:36 UTC
From: timshaw at mail dot usa dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.2.5 OS: Win32
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: timshaw at mail dot usa dot com
New email:
PHP Version: OS:

 

 [2008-01-15 02:24 UTC] timshaw at mail dot usa dot com
Description:
------------
Shouldn't unset of a declared property still leave the property as a declared property, so that the set overload will not later be used on it?

It is cool to unset things once their value becomes invalid to catch errors using the invalid value. However, I could understand that this overload problem is actually an undocumented feature if the person who implemented overloads decided that everybody should be able to overload everything, even declared properties, so this was put in to allow that.... Too bad that doesn't accomodate those of us who don't want to use overloads for everything, just some things.


Reproduce code:
---------------
<?php
class c {
  public $x ;
  public function __set($nm, $val) { echo "overloaded __set($nm, $val) ;\n" ; }
  public function __isset($nm) { echo "overloaded __isset($nm) ;\n" ; }
  public function __unset($nm) { echo "overloaded __unset($nm) ;\n" ; }
}
$c = new c ;
echo "Does not overload, just as expected and documented, because \$x is declared property\n" ;
echo "\$c->x = ", $c->x = 5, "\n" ;
echo "Does not overload, just as expected, because \$x is declared property\n" ;
echo "isset(\$c->x) = ", isset($c->x)? 'True': 'False', "\n" ;
echo "Does not use overload __unset, just as expected, because \$x is declared property\n" ;
echo "unset(\$c->x)\n" ;
unset($c->x) ;
echo "Here's the problem- \$x is declared public property, but now it's using overloaded set!\n" ;
echo "\$c->x = 5 ...  " ; $c->x = 5 ;
?>


Expected result:
----------------
The "overloaded ..." should not appear because only the declared property $x is used.

Actual result:
--------------
This does not call overload, just as expected and documented, because $x is declared property
$c->x = 5
This does not call overload, just as expected, because $x is declared property
isset($c->x) = True
This does not go though __unset, just as expected, because $x is declared property
unset($c->x)
Here's the problem- $x is declared public property, but now it's using overloaded set!
$c->x = 5 ...  overloaded __set(x, 5) ;

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-01-28 23:36 UTC] tony2001@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


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 09:01:28 2024 UTC