Clint M Priest | 1 Mar 01:45 2012

RE: [PHP-DEV] [Draft RFC] Object Casting and Assignment Handlers

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.

I am interested in object natives though, which this is leading in the direction of.

-Clint

-----Original Message-----
From: Stas Malyshev [mailto:smalyshev <at> sugarcrm.com] 
Sent: Wednesday, February 29, 2012 1:48 AM
To: Anthony Ferrara
Cc: internals <at> 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
(Continue reading)

jpauli | 1 Mar 11:40 2012
Picon
Picon

Re: [PHP-DEV] [Draft RFC] Object Casting and Assignment Handlers

On Thu, Mar 1, 2012 at 1:45 AM, Clint M Priest <cpriest <at> zerocue.com> 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
(Continue reading)


Gmane