Bug #66917 [Opn->Nab]: __set will not called in any situation
| From: | requinix@php.net | Date: | Mon, 17 Mar 2014 16:21:26 +0000 |
| Subject: | Bug #66917 [Opn->Nab]: __set will not called in any situation | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-184814@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=66917&edit=1
ID: 66917
Updated by: requinix@php.net
Reported by: daniel dot chobe at nextiraone dot eu
Summary: __set will not called in any situation
-Status: Open
+Status: Not a bug
Type: Bug
Package: Class/Object related
Operating System: Irrelevant
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
That is true: when your __set() defined $name on the instance it was no longer "not
defined" and thus the method will not be called for it in the future.
If you don't want that to happen then don't define $name on the instance - stick it in an
array or something.
Previous Comments:
------------------------------------------------------------------------
[2014-03-17 14:04:32] daniel dot chobe at nextiraone dot eu
Description:
------------
The __set Magic Method will be called only one time if the variable is not defined. If the variable
defined, __set will not called anymore, but the value is changed. See Example.
Test script:
---------------
<?php
class test {
public function __set($name, $value) {
echo "Set $name to $value" . PHP_EOL;
$this->$name = $value;
}
}
$test = new test();
$test->foo = 1;
echo 'Foo: ' . $test->foo . PHP_EOL;
$test->foo = 2;
echo 'Foo: ' . $test->foo . PHP_EOL;
Expected result:
----------------
Set foo to 1
Foo: 1
Set foo to 2
Foo: 2
Actual result:
--------------
Set foo to 1
Foo: 1
Foo: 2
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=66917&edit=1