php.net |  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: daniel dot chobe at nextiraone dot eu
New email:
PHP Version: OS:

 

 [2014-03-17 14:04 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-03-17 16:21 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2014-03-17 16:21 UTC] 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-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] requinix@php.net
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: Thu Apr 25 09:01:29 2024 UTC