Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:58113 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 2275 invoked from network); 27 Feb 2012 02:50:59 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Feb 2012 02:50:59 -0000 Authentication-Results: pb1.pair.com smtp.mail=ircmaxell@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ircmaxell@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.49 as permitted sender) X-PHP-List-Original-Sender: ircmaxell@gmail.com X-Host-Fingerprint: 209.85.216.49 mail-qw0-f49.google.com Received: from [209.85.216.49] ([209.85.216.49:54620] helo=mail-qw0-f49.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 0A/CA-40985-39FEA4F4 for ; Sun, 26 Feb 2012 21:50:59 -0500 Received: by qadc14 with SMTP id c14so1567388qad.8 for ; Sun, 26 Feb 2012 18:50:56 -0800 (PST) Received-SPF: pass (google.com: domain of ircmaxell@gmail.com designates 10.229.137.137 as permitted sender) client-ip=10.229.137.137; Authentication-Results: mr.google.com; spf=pass (google.com: domain of ircmaxell@gmail.com designates 10.229.137.137 as permitted sender) smtp.mail=ircmaxell@gmail.com; dkim=pass header.i=ircmaxell@gmail.com Received: from mr.google.com ([10.229.137.137]) by 10.229.137.137 with SMTP id w9mr6557467qct.16.1330311056893 (num_hops = 1); Sun, 26 Feb 2012 18:50:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=Ei1cdsl0DHhUBT6wXh2Ra08ffYTH2PW+8ZtigRnuUk0=; b=tAVNlas/cGl2pPOm5IG2jo78n08HpT7iAGbVy03LPSyi8vQhL5dwRtqyHgb8WmgLfd BByjApdACizD1gyQYLtxyFkLCJnPBX/yNmw7v+5X18TCpEfx2a6xKJK5+HiBzyBri522 u8K19I5x7iXnMa+eNcD6740I6nkpMhpPbLtRw= MIME-Version: 1.0 Received: by 10.229.137.137 with SMTP id w9mr5401727qct.16.1330311056758; Sun, 26 Feb 2012 18:50:56 -0800 (PST) Received: by 10.229.166.202 with HTTP; Sun, 26 Feb 2012 18:50:56 -0800 (PST) In-Reply-To: <4F4AA807.20404@gmail.com> References: <4F4AA807.20404@gmail.com> Date: Sun, 26 Feb 2012 21:50:56 -0500 Message-ID: To: =?ISO-8859-1?Q?=C1ngel_Gonz=E1lez?= Cc: internals@lists.php.net Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Object Casting - An Alternative to Type Hinting From: ircmaxell@gmail.com (Anthony Ferrara) I fail to see how you would do it via a register function... Unless you mean a call-chain of callbacks to try to "cast" with a "from" and a "to" parameter: spl_autocast_register(function($from, $to) { if ($to =3D=3D 'Integer') { return new Integer((int) $from); } }); That could have extreme performance penalties, as every callback in the chain (at least up to a valid cast) would then need to be called for every single cast operation. Not to mention that you're now externalizing where the cast happens into a non-obvious and non-extendable spot (meaning that you're removing the possibility of modifying behavior via polymorphism)... I prefer the concept of binding the cast operations (two, for symmetry) to the class itself, as it localizes the functionality to that class, and is quite predictable and extendable. If I missed the point you were trying to make, please elaborate. Thanks, Anthony 2012/2/26 =C1ngel Gonz=E1lez : > I just realised that if it were going to add magic casting, it could as w= ell > be done with a spl_autocast_register(), so that you could either cast thi= ngs > when they match, throw an exception, etc. =A0(there should be some defaul= t > value dynamic typing, so the perfomance wouldn't hurt) . > > I don't think that's the perfect solution, though. >