|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-01-28 23:36 UTC] tony2001@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Dec 15 03:00:01 2025 UTC |
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) ;