Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:46667 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 49244 invoked from network); 13 Jan 2010 02:29:46 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Jan 2010 02:29:46 -0000 Authentication-Results: pb1.pair.com header.from=oorza2k5@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=oorza2k5@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.78.25 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: oorza2k5@gmail.com X-Host-Fingerprint: 74.125.78.25 ey-out-2122.google.com Received: from [74.125.78.25] ([74.125.78.25:56452] helo=ey-out-2122.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C3/3F-06421-8103D4B4 for ; Tue, 12 Jan 2010 21:29:45 -0500 Received: by ey-out-2122.google.com with SMTP id 9so5129154eyd.39 for ; Tue, 12 Jan 2010 18:29:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=bpjhZKA2v6t5xtANw+pWXc9EuWV/Nl76Hmwh2runk3A=; b=JZBIJoRMKv6sdx3mz71aBq50BbrZyoZmDDGsC0iW9VMN7N83qOXMP8u5R1FWaV6qO1 kRf/5CRvqxyGsLtSNTPVG1dcBNapj62F83pGCk+73XSj44CCDlJ91sJ6LlscG0RJ6oj6 uscryBlk/0h1IatGGLRwezML0iQjtiUiREQAI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=Nn5guQ2Sbv5guwX+1oH4O0lwBrlXZBH3O5pm0zAa15r4gELAWjl3k4Hae1sQqj9Dp5 RPArTmIuxBCMlPbuLXd9eUUm4opGSyZWl9Lprt/1p5uJHIGGlOZ1yIo/3KILVqzifsBq NT4nT96YBOOw17DZz9WprDUS2LDOjPk497toM= MIME-Version: 1.0 Received: by 10.216.90.137 with SMTP id e9mr3372721wef.141.1263349781204; Tue, 12 Jan 2010 18:29:41 -0800 (PST) In-Reply-To: References: <3A.94.26332.3E9EB4B4@pb1.pair.com> <68de37341001121810x10be424fu842402a398d3709e@mail.gmail.com> Date: Tue, 12 Jan 2010 21:29:41 -0500 Message-ID: <68de37341001121829p3a2f6a62y6eb2a45863e62ae6@mail.gmail.com> To: mm w <0xcafefeed@gmail.com> Cc: Chris Stockton , internals@lists.php.net Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] __toString(), __toArray() From: oorza2k5@gmail.com (Eddie Drapkin) What you're proposing is just forcing __call, _callStatic, __get and __set into a single method, which does nothing to reduce the amount of magic, only obfuscate it. And it certainly offers no alternative to "__cast", at least not that I can see. On Tue, Jan 12, 2010 at 9:11 PM, mm w <0xcafefeed@gmail.com> wrote: > the multiplication of magic, the pointed point, need to read more careful= ly > > On Tue, Jan 12, 2010 at 6:10 PM, Eddie Drapkin wrote= : >> How does this have *anything* to do with the discussion at hand? >> >> On Tue, Jan 12, 2010 at 9:09 PM, mm w <0xcafefeed@gmail.com> wrote: >>> don't worry it's only for people who are working with MVC and >>> RootObject structure, there is too much magics already and __cast is >>> not needed at all, >>> as we cannot monkey patch to add an observer on itself, a nice >>> solution should have a catchable object so __catch any calls >>> >>> function __catch($data, $type) { >>> =C2=A0 =C2=A0if (method =3D=3D $type) { >>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (data[selector] =3D 'setValue' && observ= edValueForKeyPath) { >>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 $this->_setValue(($data['arg'= ]); >>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return; >>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 } >>> =C2=A0 =C2=A0} >>> =C2=A0 =C2=A0continue_natural_call(); >>> } >>> >>> we could imagine to have a root-object-built-in-class that is >>> naturally observable, or a root classObject at all, anyway it's only >>> something for people who are doing OO programming, >>> so don't worry >>> >>> On Tue, Jan 12, 2010 at 2:40 PM, Chris Stockton >>> wrote: >>>> Hello, >>>> >>>> On Mon, Jan 11, 2010 at 8:32 PM, mm w <0xcafefeed@gmail.com> wrote: >>>>> cast is not needed in PHP >>>>> >>>>> i 'd rather be more interesting in >>>>> >>>>> class Obj { >>>>> =C2=A0 =C2=A0 function __catch($data, $type) { >>>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0//$type [ static_method, met= hod, get_property, set_property] >>>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (observed && =C2=A0$type = =3D=3D set_property && somevalueIsObserved) { >>>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0$observ= er->notify("somevalue::valueWillChanged"); >>>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0$this->= somevalue =3D $data['somevalue']; >>>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0$observ= er->notify("somevalue::valueDidChanged"); >>>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0} else { >>>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0continu= e__call(); >>>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0} >>>>> =C2=A0 =C2=A0 } >>>>> } >>>> >>>> What? ... >>>> >>>>>> Etienne Kneuss wrote: >>>>>> This is where operator over-loading would be useful however perhaps = only >>>>>> explicit casts would make sense here. >>>> >>>> I beleive adding a __cast(string $type) would be a useful feature for >>>> me, very often I have a toArray method defined. I agree with you that >>>> due to unexpected edge cases with operator precedence and general type >>>> juggling that __cast should only be called on explicit (cast). >>>> >>>> I.E.: >>>> class Int { public function __cast($type) { return 'int' =3D=3D $type = ? 15 : 0; } } >>>> $r =3D new Int; >>>> >>>> var_dump($r + 1); // 2 >>>> var_dump((int) $r + 1); // 16 >>>> var_dump((bool) $r + 1); // 1 >>>> >>> >>> -- >>> PHP Internals - PHP Runtime Development Mailing List >>> To unsubscribe, visit: http://www.php.net/unsub.php >>> >>> >> >