Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:22636 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 59321 invoked by uid 1010); 1 Apr 2006 08:13:11 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 59306 invoked from network); 1 Apr 2006 08:13:11 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Apr 2006 08:13:11 -0000 X-Host-Fingerprint: 194.109.193.120 unknown Linux 2.5 (sometimes 2.4) (4) Received: from ([194.109.193.120:44691] helo=mx1.moulin.nl) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id CE/C7-28679-7163E244 for ; Sat, 01 Apr 2006 03:13:11 -0500 Received: from localhost (localhost [127.0.0.1]) by mx1.moulin.nl (Postfix) with ESMTP id 3A9401A4DE5; Sat, 1 Apr 2006 10:13:11 +0200 (CEST) Received: from mx1.moulin.nl ([127.0.0.1]) by localhost (moulin [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 05329-08; Sat, 1 Apr 2006 10:13:09 +0200 (CEST) Received: from [10.0.13.55] (ip129-15-211-87.adsl2.versatel.nl [87.211.15.129]) by mx1.moulin.nl (Postfix) with ESMTP id 3B8051A4DCF; Sat, 1 Apr 2006 10:13:09 +0200 (CEST) Message-ID: <442E3611.6070306@iamjochem.com> Date: Sat, 01 Apr 2006 10:13:05 +0200 User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317) X-Accept-Language: en-us, en MIME-Version: 1.0 To: "Unknown W. Brackets" Cc: internals@lists.php.net References: <442DCE06.8070307@iamjochem.com> In-Reply-To: X-Enigmail-Version: 0.89.5.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: amavisd-new at moulin.nl Subject: Re: [PHP-DEV] Re: __set() / __get() : limitation and/or unintentional behavoiur? From: jochem@iamjochem.com (Jochem Maas) Unknown W. Brackets wrote: > 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 I know these things. > array. It may help to think of it like this: it's doesn't because object != array. as long as you stick to nesting objects in this way everything is fine because __set() is called on the object returned by __get() at the previous level - meaning control is maintained by the object. basically if I have an overloaded property that is an array I can bork it's contents completely from outside of the object and the object doesn't get anything to say about it. medical analogy to observed behaviour: if your liver was an array, then I could operate on your liver without you ever knowing - heck I could remove it completely - regardless of any medical training. can I assume you would rather keep control of who does what to your liver? > > $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? I'd expect that, __set() be called on $t in the first line and on the second line __get() to be called on $t and __set() on object $t->insideClass. assuming that class T is defined as in my previous post. > 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. I'm not asking how it works. or how to use it but whether it's intended. (something which STFW or RTFM doesn't enlighten me about) which is why I ask the people that wrote the functionality (I figure they would know what the intention is/was). let me guess, you think it belongs on php-generals? well I'm asking this question based on a discussion held there - and nobody offered any kind of answer ... in fact I justed checked and one of the other guys on the thread in question (subject: "Overloading Limitation- Can Someone Confirm?") now has a variation of the code we were playing with that segfaults in 5.0.4 and causes a 'FATAL: emalloc()' error in 5.1.1 (I don't have a newer version at hand but the other guy reports very odd behaviour in (I assume in 5.1.2) the code in question is: array[$key]; } public function __set( $key, $value ) { echo "Setting $key\n"; $this->array[$key] = $value; } } $t = new T; $t->insideArray = array('a' => 'A', 'b' => 'B', 'c' => 'C'); foreach ($t->insideArray as $k => $v) { $t->insideArray[$k] = null; } if (count($t->insideArray) > 0) { foreach ($t->insideArray as $k => $v) { echo $v; } } var_dump($t); ?> 5.0.4 OUTPUT: ======================================== Setting insideArray Getting insideArray Getting insideArray Getting insideArray Getting insideArray Getting insideArray Segmentation fault 5.1.1 OUTPUT: ======================================== Setting insideArray Getting insideArray Getting insideArray Getting insideArray Getting insideArray Getting insideArray Getting insideArray FATAL: emalloc(): Unable to allocate 1916888421 bytes I have sneaking suspicion that that's not meant to happen. rgds, Jochem >