|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66917 __set will not called in any situation
Submitted: 2014-03-17 14:04 UTC Modified: 2014-03-18 16:26 UTC
From: daniel dot chobe at nextiraone dot eu Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: Irrelevant OS: Irrelevant
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
13 + 14 = ?
Subscribe to this entry?

 [2014-03-17 14:04 UTC] daniel dot chobe at nextiraone dot eu
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:

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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2014-03-17 16:21 UTC]
-Status: Open +Status: Not a bug
 [2014-03-17 16:21 UTC]
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-18 06:35 UTC] 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-18 16:26 UTC]
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.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Jun 15 17:01:31 2024 UTC