Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:46659 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 12843 invoked from network); 12 Jan 2010 22:41:01 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Jan 2010 22:41:01 -0000 Authentication-Results: pb1.pair.com header.from=chrisstocktonaz@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=chrisstocktonaz@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.222.194 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: chrisstocktonaz@gmail.com X-Host-Fingerprint: 209.85.222.194 mail-pz0-f194.google.com Received: from [209.85.222.194] ([209.85.222.194:37041] helo=mail-pz0-f194.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8C/68-06421-D7AFC4B4 for ; Tue, 12 Jan 2010 17:41:01 -0500 Received: by pzk32 with SMTP id 32so514303pzk.29 for ; Tue, 12 Jan 2010 14:40:58 -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=AT5eP8JOkneP49CYYsVrM7r7er6iSCqYBr280F24YBE=; b=c8rDnctq2uMF0h7LtpPYhnvt2H95vMCNWS1qloGsPKBwXV7xi3Jwfx3OtrFeA8NqRl K6as/AJPACv3tkJvYl4fuOy+xPKPGAJZvu4oAmMeVSWjOkt2lhlK7N32F7uBeJysdVaq RSnsig796WCueOgyEu6E4k54SOq4DswQsS3c0= 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=UB0Uc9TS5ool2BCqWOeYyfPB8HUW6ehJeTe/upy8CS1+ZAk/z4tMEPLYEF7TB7z+E1 uGoqLwbl7r/wyZ0nweacv1AL+kV8JCSOvSHJePIszzRTJFtgcd0EJtw7NzGF/iuI0mlV T1OAnqMwewwkE+HTOfL+xkEH/G2OgyTr4MAaE= MIME-Version: 1.0 Received: by 10.142.207.16 with SMTP id e16mr1906510wfg.281.1263336058784; Tue, 12 Jan 2010 14:40:58 -0800 (PST) In-Reply-To: References: <3A.94.26332.3E9EB4B4@pb1.pair.com> Date: Tue, 12 Jan 2010 15:40:58 -0700 Message-ID: To: mm w <0xcafefeed@gmail.com> Cc: internals@lists.php.net Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] __toString(), __toArray() From: chrisstocktonaz@gmail.com (Chris Stockton) 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 { > =A0 =A0 function __catch($data, $type) { > =A0 =A0 =A0 =A0 =A0 =A0//$type [ static_method, method, get_property, set= _property] > =A0 =A0 =A0 =A0 =A0 =A0if (observed && =A0$type =3D=3D set_property && so= mevalueIsObserved) { > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0$observer->notify("somevalue::valueWil= lChanged"); > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0$this->somevalue =3D $data['somevalue'= ]; > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0$observer->notify("somevalue::valueDid= Changed"); > =A0 =A0 =A0 =A0 =A0 =A0} else { > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0continue__call(); > =A0 =A0 =A0 =A0 =A0 =A0} > =A0 =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