Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:46664 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 43937 invoked from network); 13 Jan 2010 02:09:29 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Jan 2010 02:09:29 -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:35286] helo=mail-ew0-f219.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B6/1E-06421-85B2D4B4 for ; Tue, 12 Jan 2010 21:09:29 -0500 Received: by ewy19 with SMTP id 19so16315869ewy.1 for ; Tue, 12 Jan 2010 18:09:26 -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=sXmEwvHrRpDH/oo+W9RhgJ2jpYzPskx5xy6Fl7yjrFo=; b=i6s9lVpZPmFGYnENPycwNOUOqyH8GANsc9QaUFHddAXUcq4y4boz3COH67rfGioPfj Yk3C/ufawOSJBeHIOvF0KSE549tBsa+uN95daVEDm4UHfzPIAZrRJZQbnuPe3vDZzT1U FWuRuL9jhwKLTOogBYFB7UTSMbE7hhIs2hvoY= 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=n7Q3RuwWg7dPWocRekNrZ64llyD/32dJRCeDLqOObLfy/xaLvBg02Uk9O/t/qPAnBk wQjy+qxgnoOcsjT4JH1OXdHHm4PpHRR4HI1M4IHmt3sB29ky0tvzfnoLQxfialbzZnj/ edzbvDfUMTVZPRXZbfGXa8JDI67/gRb2vlBrs= MIME-Version: 1.0 Received: by 10.216.87.197 with SMTP id y47mr915236wee.202.1263348565962; Tue, 12 Jan 2010 18:09:25 -0800 (PST) In-Reply-To: References: <3A.94.26332.3E9EB4B4@pb1.pair.com> Date: Tue, 12 Jan 2010 18:09:25 -0800 Message-ID: To: Chris Stockton 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) 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) { if (method =3D=3D $type) { if (data[selector] =3D 'setValue' && observedValueForKeyPath) { $this->_setValue(($data['arg']); return; } } 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=A0 function __catch($data, $type) { >> =C2=A0 =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 =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$observer-= >notify("somevalue::valueWillChanged"); >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0$this->som= evalue =3D $data['somevalue']; >> =C2=A0 =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 =C2=A0} else { >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0continue__= 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 onl= y >>> 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 ? 1= 5 : 0; } } > $r =3D new Int; > > var_dump($r + 1); // 2 > var_dump((int) $r + 1); // 16 > var_dump((bool) $r + 1); // 1 >