Re: __set() / __get() : limitation and/or unintentional behavoiur?
| From: | Unknown W. Brackets | Date: | Sat, 01 Apr 2006 07:05:56 +0000 |
| Subject: | Re: __set() / __get() : limitation and/or unintentional behavoiur? | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-22635@lists.php.net to get a copy of this message | ||
The __set() method is called when a property of a class is set, __get() when a property is retrieved.
An array is simple a way of listing things; the array itself is a piece of data. When you set a key in that array, you are not setting the array. It may help to think of it like this:
$t = new T;
$t->insideClass = new T;
$t->insideClass->test = "testing!";
In this case, should __set() be called for both lines? Or only for the first? An array is exactly the same, except you cannot define a __set() method on it.
Anyway, I don't think this question belongs in internals, imho.
-[Unknown]
-------- Original Message --------
I ran the following code on 5.0.4 and 5.1.0 with identical results... Could someone shed light one whether the observed behaviour is intentional and/or correct? I expected that one of the following would occur (which obviously doesn't :-): 1. the line commented with 'SET 2' would trigger a call to __set() (which should fail?). 2. the key "test" would be set in the array returned by __get() but not it the relevant array stored in $this->array["insideArray"]. The reason I question whether what si observed below is wanted behaviour is because I thought the __set() functionality was there to be able to protect/control what stuffed into an object ... but apparently it's rather easy to side step. tia, Jochem