Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:58115 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 14880 invoked from network); 27 Feb 2012 07:40:20 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Feb 2012 07:40:20 -0000 Authentication-Results: pb1.pair.com header.from=simonsimcity@googlemail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=simonsimcity@googlemail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain googlemail.com designates 209.85.214.170 as permitted sender) X-PHP-List-Original-Sender: simonsimcity@googlemail.com X-Host-Fingerprint: 209.85.214.170 mail-tul01m020-f170.google.com Received: from [209.85.214.170] ([209.85.214.170:38857] helo=mail-tul01m020-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 59/BC-40985-2633B4F4 for ; Mon, 27 Feb 2012 02:40:18 -0500 Received: by obbup3 with SMTP id up3so5225110obb.29 for ; Sun, 26 Feb 2012 23:40:15 -0800 (PST) Received-SPF: pass (google.com: domain of simonsimcity@googlemail.com designates 10.182.124.41 as permitted sender) client-ip=10.182.124.41; Authentication-Results: mr.google.com; spf=pass (google.com: domain of simonsimcity@googlemail.com designates 10.182.124.41 as permitted sender) smtp.mail=simonsimcity@googlemail.com; dkim=pass header.i=simonsimcity@googlemail.com Received: from mr.google.com ([10.182.124.41]) by 10.182.124.41 with SMTP id mf9mr4509450obb.65.1330328415621 (num_hops = 1); Sun, 26 Feb 2012 23:40:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=aXFSDoSwW1VNguWrwD1Ik2plAatQcYBWA9qDvg4sv00=; b=PijWax0iSvva82qjxHXrXDDvTUnHOO/knj3iaPsgHaBtGpfNQwgmjGMPJQ5/Kyyd2J 7wQEOhI1821vdcKalQcYyutEwNoY9q5r8vkRTHs3MxQ/tPw30Fv0AESXfPaxJT6kZCng MjUVc2JzhzcDAQLd9EbCpZ3zlrJDWLQ1IP+ns= MIME-Version: 1.0 Received: by 10.182.124.41 with SMTP id mf9mr4009170obb.65.1330328415548; Sun, 26 Feb 2012 23:40:15 -0800 (PST) Received: by 10.60.7.229 with HTTP; Sun, 26 Feb 2012 23:40:15 -0800 (PST) In-Reply-To: References: <4F4AA807.20404@gmail.com> Date: Mon, 27 Feb 2012 08:40:15 +0100 Message-ID: To: Anthony Ferrara Cc: =?UTF-8?B?w4FuZ2VsIEdvbnrDoWxleg==?= , internals@lists.php.net Content-Type: multipart/alternative; boundary=f46d0444eebba4b51604b9ed3859 Subject: Re: [PHP-DEV] Object Casting - An Alternative to Type Hinting From: simonsimcity@googlemail.com (Simon Schick) --f46d0444eebba4b51604b9ed3859 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi, This does not seem like a good way for me ... Think about combining many scripts. It's for example quite usual to use Symfony and parts of Zend Framework together. Think about what will happen if the one framework uses another autocast logic ... Bye Simon 2012/2/27 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 =C3=81ngel Gonz=C3=A1lez : > > I just realised that if it were going to add magic casting, it could as > well > > be done with a spl_autocast_register(), so that you could either cast > things > > when they match, throw an exception, etc. (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. > > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --f46d0444eebba4b51604b9ed3859--