|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2015-12-23 13:44 UTC] nowm at yandex dot ru
[2015-12-23 18:15 UTC] requinix@php.net
-Status: Open
+Status: Not a bug
[2015-12-23 18:15 UTC] requinix@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 01:00:02 2025 UTC |
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