Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:46672 Return-Path: <0xcafefeed@gmail.com> Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 62790 invoked from network); 13 Jan 2010 04:09:52 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Jan 2010 04:09:52 -0000 Authentication-Results: pb1.pair.com smtp.mail=0xcafefeed@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=0xcafefeed@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.219.219 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: 0xcafefeed@gmail.com X-Host-Fingerprint: 209.85.219.219 mail-ew0-f219.google.com Received: from [209.85.219.219] ([209.85.219.219:35879] helo=mail-ew0-f219.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 39/B1-06421-F874D4B4 for ; Tue, 12 Jan 2010 23:09:52 -0500 Received: by ewy19 with SMTP id 19so16387984ewy.1 for ; Tue, 12 Jan 2010 20:09:48 -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=RHerVNxcAfSYF/yQ/yBTxFcU4gFAuL6XHTdUysZ8h0s=; b=Cs4bNpk6cUPtC9ifnA9W0X2Hwm/BO9CPBRSExCFl0cBxcR4nvf7zPjEr14pRgCjfMS +kLD51kG8L0hjlnOBy7xIC2aUaDcclax1dSILTYvxV6QqwEBwq5ayuDtXA+KtEJNxF6v Zn7hWt2v19BW5MmNmfKYt/6AAUnJBlTwmJr1E= 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=L+2LnBdmXdlf+0i+YEc9agKKC+3WCUp7EOtBvqng7yIBy1ULzGHohUH8QsR2e9aEli f4eCkeo42lV3VArDK4HQ5mDfhgyl6qfaDXq2CWsUewypN0iU6IH4ic7a6n7PPI7Ccvgl FW4Fq825cMe2ut+YNfNiy+OXV4nEVJACLvzww= MIME-Version: 1.0 Received: by 10.216.86.200 with SMTP id w50mr3550526wee.173.1263355788278; Tue, 12 Jan 2010 20:09:48 -0800 (PST) In-Reply-To: <4B4D371D.3010200@warpmail.net> References: <3A.94.26332.3E9EB4B4@pb1.pair.com> <68de37341001121810x10be424fu842402a398d3709e@mail.gmail.com> <68de37341001121829p3a2f6a62y6eb2a45863e62ae6@mail.gmail.com> <4B4D371D.3010200@warpmail.net> Date: Tue, 12 Jan 2010 20:09:48 -0800 Message-ID: To: Clint Priest Cc: internals@lists.php.net Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] __toString(), __toArray() From: 0xcafefeed@gmail.com (mm w) I don't move any magics,I am worried about your knowledge of php, there's people to give you money ? weird, set get call are only call when something doesn't exist catch or catch-able concept is to be able to catch any existing calls no the dynamic ones. On Tue, Jan 12, 2010 at 6:59 PM, Clint Priest wrote: > > > Eddie Drapkin wrote: >> >> 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. =C2=A0And it certainly offers no alternative t= o >> "__cast", at least not that I can see. > > I agree, moving all magic to a single function doesn't help the situation= at > all, it simply complicates it. > > All this talk of "too many magic functions" is a little comical, its all > trying to overcome operator overloading type functionality in other > languages. > > __get()/__set() would be equivalent to getters/setters supported by the c= # > language > > __toString(), __toArray() would be equivalent to operator String() in c++= ( > if I remember correctly ) > > I would definitely love to be able to, at the very least, cast an object = to > an array but I figured a more general purpose __cast() would be most > beneficial to all. > > I think the ambiguity question for some functions accepting mixed as a > parameter type could be solved in aforementioned ways. > >> 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 >>> carefully >>> >>> 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 if (method =3D=3D $type) { >>>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0if (data[selector] =3D 'setValue' && obser= vedValueForKeyPath) { >>>>> =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=A0return; >>>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0} >>>>> =C2=A0 } >>>>> =C2=A0 continue_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=A0function __catch($data, $type) { >>>>>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 //$type [ static_method, method,= get_property, >>>>>>> set_property] >>>>>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (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 $observer->= notify("somevalue::valueWillChanged"); >>>>>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 $this->some= value =3D $data['somevalue']; >>>>>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 $observer->= notify("somevalue::valueDidChanged"); >>>>>>> =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 continue__c= all(); >>>>>>> =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 perhap= s >>>>>>>> only >>>>>>>> explicit casts would make sense here. >>>>>> >>>>>> I beleive adding a __cast(string $type) would be a useful feature fo= r >>>>>> me, very often I have a toArray method defined. I agree with you tha= t >>>>>> due to unexpected edge cases with operator precedence and general ty= pe >>>>>> juggling that __cast should only be called on explicit (cast). >>>>>> >>>>>> I.E.: >>>>>> class Int { public function __cast($type) { return 'int' =3D=3D $typ= e ? 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 >>>>> >>>>> > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > >