The __toArray can be useful if you want to perform array functions on the
object (E.G array_filter), otherwise I think it would be very useful if the
array functions can accept an object implementing ArrayAccess as well
instead of just an array
On May 7, 2013 8:40 PM, "Nikita Popov" <nikita....@gmail.com> wrote:

> On Sat, May 4, 2013 at 5:31 PM, Oleku Konko <oleku.ko...@yahoo.com> wrote:
>
> > Quick Observations :
> >
> > I had this issue (
> > http://stackoverflow.com/questions/16375331/increment-on-tostring ) and
> > it kept me thinking why no error was returned, then i stumble up this
> RFC :
> >  https://wiki.php.net/rfc/object_cast_to_types
> >
> > The patch is basic , simple and working and it should
> > be seriously considered in 5.5.  I want to  believe if
> > https://github.com/php/php-src/pull/334 can make it to PHP 5.5 then we
> > should give object_cast_to_types the same opportunity except they are
> > string objections why it should not be so
> >
>
> I don't think that this would be particularly useful and as such I don't
> think we need it. The idea of doing some meaningful operation when writing
> $obj + 1 is nice, but only if you have actual operator overloading and can
> compute the result of that expression yourself. If you don't have this
> possibility and only get to cast $a to an integer/float, then the whole
> thing becomes rather useless. The only thing it could be used for are thin
> wrappers around integers/floats and I don't see why one would want to do
> such a thing (especially as you get back a number and *not* a wrapper
> object).
>
> Thus, __toScalar(), __toInt(), __toFloat() seem pretty useless. The only
> thing that might have some merit is __toArray(). But there again, I'm not
> really sure what it gives us. After all we already have Traversable and
> ArrayAccess, so we can already make an object behave pretty much like an
> array.
>
> Nikita
>

Reply via email to