Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:58406 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 14401 invoked from network); 1 Mar 2012 10:40:49 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Mar 2012 10:40:49 -0000 Authentication-Results: pb1.pair.com header.from=julienpauli@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=julienpauli@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.170 as permitted sender) X-PHP-List-Original-Sender: julienpauli@gmail.com X-Host-Fingerprint: 209.85.215.170 mail-ey0-f170.google.com Received: from [209.85.215.170] ([209.85.215.170:57380] helo=mail-ey0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CF/02-46815-F225F4F4 for ; Thu, 01 Mar 2012 05:40:48 -0500 Received: by eaao10 with SMTP id o10so124332eaa.29 for ; Thu, 01 Mar 2012 02:40:44 -0800 (PST) Received-SPF: pass (google.com: domain of julienpauli@gmail.com designates 10.213.105.70 as permitted sender) client-ip=10.213.105.70; Authentication-Results: mr.google.com; spf=pass (google.com: domain of julienpauli@gmail.com designates 10.213.105.70 as permitted sender) smtp.mail=julienpauli@gmail.com; dkim=pass header.i=julienpauli@gmail.com Received: from mr.google.com ([10.213.105.70]) by 10.213.105.70 with SMTP id s6mr1679233ebo.45.1330598444862 (num_hops = 1); Thu, 01 Mar 2012 02:40:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type; bh=a0irfTagm7RwyRSzOvrKm/TzSDoOhRe9Rqn8DjHLvlM=; b=bKIlqNdEo8nM/AhSow38E35y4e1sxVNIp+WHmMBV69Yy1EDvKLF/QSDBFP7U4Fc/Sk ig4jgOqWn6bdu1p4jb9v9vrEoH9B9qAvCOM1kb50gcnO9d53y5ngXZmwnprG2VoNs8/L jje845mPOXXuwmoRI4x4VShAQQbEVT6pZIy9o= Received: by 10.213.105.70 with SMTP id s6mr1296312ebo.45.1330598444702; Thu, 01 Mar 2012 02:40:44 -0800 (PST) MIME-Version: 1.0 Sender: julienpauli@gmail.com Received: by 10.213.29.2 with HTTP; Thu, 1 Mar 2012 02:40:04 -0800 (PST) In-Reply-To: <9570D903A3BECE4092E924C2985CE485515FC4EC@MBX202.domain.local> References: <4F4DD837.9090705@sugarcrm.com> <9570D903A3BECE4092E924C2985CE485515FC4EC@MBX202.domain.local> Date: Thu, 1 Mar 2012 11:40:04 +0100 X-Google-Sender-Auth: jxVnBh5bH8AH0Ay10CcM97jeZMM Message-ID: To: Clint M Priest Cc: Stas Malyshev , Anthony Ferrara , "internals@lists.php.net" Content-Type: multipart/alternative; boundary=0015174c4152a29e1404ba2c178d Subject: Re: [PHP-DEV] [Draft RFC] Object Casting and Assignment Handlers From: jpauli@php.net (jpauli) --0015174c4152a29e1404ba2c178d Content-Type: text/plain; charset=ISO-8859-1 On Thu, Mar 1, 2012 at 1:45 AM, Clint M Priest wrote: > As much as I would love to have __castTo() and __assign() I have to agree > with Stas here that it fundamentally changes the mechanics of if($object) > and unfortunately turns that simple if statement into a possible hour long > hunt to find the code that is doing the damage, if it is even considered a > possibility by someone reading the code. > > For the record, I really have only ever needed something like __toArray() > so that objects implementing ArrayAccess could be passed to array internal > functions. > In my own advice, this is far more important than every other thing, really. That could require adding __toArray() to ArrayAccess, which would BC break, but that has to be discussed. Why not another RFC about that ? Also, one should keep the past decisions in his head, thus a refreshing about ArrayAccess and current status could be good. Please, see http://devzone.zend.com/1124/zend-weekly-summaries-issue-361/#Heading3 http://devzone.zend.com/284/zend-weekly-summaries-issue-211/#Heading5 for example. My thoughts Julien.P > > I am interested in object natives though, which this is leading in the > direction of. > > -Clint > > -----Original Message----- > From: Stas Malyshev [mailto:smalyshev@sugarcrm.com] > Sent: Wednesday, February 29, 2012 1:48 AM > To: Anthony Ferrara > Cc: internals@lists.php.net > Subject: Re: [PHP-DEV] [Draft RFC] Object Casting and Assignment Handlers > > Hi! > > > Hey all, > > > > I've created a draft version of the RFC for implementing __castTo() > > and __assign(): > > > > https://wiki.php.net/rfc/object_cast_magic > > I think having cast method may have merits, though use cases where objects > need to be converted to scalars that aren't string are very limited, and > cases where they need to do so transparently are almost non-existent. I > think what outlined in the RFC is a backdoor operator overloading, through > rather complex and unobvious magic. My opinion is that outside of very > limited number of cases (such as implementing complex numbers or matrix > algebra - and how frequently would one need do that in PHP anyway?) > operator overloading is way more trouble than it's worth and makes code > nearly unreadable as you never know what exactly each operator does. For > example, if($object) would have completely different semantics than before, > for some objects but not other, and without any obvious clue to the user > what it actually does - and all that to save couple of keystrokes on > if($object->valid())? > > Still, if there's a valid use case found, cast magic method and "unboxing" > method may have merit. So far the cases outlined seem either too artificial > and narrow for language-level functionality, or plain wrong (like > SplFixedArray example - nothing in this proposal would enable it to work > with sort, for example). But I do not exclude other cases can exist. > > However, assignment overloading does not seem viable to me. > Also, I'm not sure how this is possible technically: $obj = {expression} > is supposed to replace $obj with the result of the expression, not call > methods on $obj. Doing otherwise would be huge change in the semantics, a > complete no go. Also, it's impossible if $obj is not set - meaning, code > $obj = 1 would mean totally different things depending on if $obj is set or > not - again, not a good idea. It also does not cover many corner cases but > I don't even want to go there since an idea to change semantics of the > assignment seems very wrong to me in principle, so no need to go into the > fine details. > -- > Stanislav Malyshev, Software Architect > SugarCRM: http://www.sugarcrm.com/ > (408)454-6900 ext. 227 > > -- > 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 > > --0015174c4152a29e1404ba2c178d--