Bug #71203 [NEW]: Ignoring class setter

From: Date: Wed, 23 Dec 2015 13:42:26 +0000
Subject: Bug #71203 [NEW]: Ignoring class setter
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-198165@lists.php.net to get a copy of this message
From: nowm at yandex dot ru Operating system: any PHP version: Irrelevant Package: Class/Object related Bug Type: Bug Bug description:Ignoring class setter Description: ------------ When a class has no "property" property and you are trying set it as $class->property = 'value', PHP is trying to use magic __set() method. It is correct behavior. But when you are trying to set it as $class->property['index'] = 'value', PHP ignores the setter, creating the "property" as a property of the class. It is incorrect behavior, because class had no "property" property, so it firstly have to use setter. Test script: --------------- <?php class SetterTester { public function __set($name, $value) { echo 'Setter is used', PHP_EOL, PHP_EOL; } } echo "Test normal version", PHP_EOL; $test = new SetterTester(); $test->property = "Some value"; echo "Test array version", PHP_EOL; $test = new SetterTester(); $test->property["index"] = "Some value"; Expected result: ---------------- Test normal version Setter is used Test array version Setter is used Actual result: -------------- Test normal version Setter is used Test array version -- Edit bug report at https://bugs.php.net/bug.php?id=71203&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=71203&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=71203&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=71203&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=71203&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=71203&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=71203&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=71203&r=needscript Try newer version: https://bugs.php.net/fix.php?id=71203&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=71203&r=support Expected behavior: https://bugs.php.net/fix.php?id=71203&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=71203&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=71203&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=71203&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=71203&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=71203&r=dst IIS Stability: https://bugs.php.net/fix.php?id=71203&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=71203&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=71203&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=71203&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=71203&r=mysqlcfg

« previous php.bugs (#198165) next »