Bug #66917 [Nab]: __set will not called in any situation
| From: | requinix@php.net | Date: | Tue, 18 Mar 2014 16:26:26 +0000 |
| Subject: | Bug #66917 [Nab]: __set will not called in any situation | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-184823@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: Not a bug
Type: Bug
Package: Class/Object related
Operating System: Irrelevant
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
Would you like to? You can go to any documentation page, click the Edit link in the top-right corner
to go to the PHP Docbook Online Editor, and make an appropriate change to the page. It can go on the
site once it's been reviewed by the documentation team.
Previous Comments:
------------------------------------------------------------------------
[2014-03-18 06:35:03] daniel dot chobe at nextiraone dot eu
Ok, I don't like this behavior, it is not logical.
But anyway is it possible to update the documentation to describe this behavior to other people?
------------------------------------------------------------------------
[2014-03-17 16:21:24] requinix@php.net
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.
------------------------------------------------------------------------
[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