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
Thanks
Oleku Konko
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_typesThe 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
This can't go into PHP 5.5 anymore as we're already past feature freeze.
Nikita
Thanks for the reply. I hope it would be part of next release eg 5.5.1
Oleku
From: Nikita Popov nikita.ppv@gmail.com
To: Oleku Konko oleku.konko@yahoo.com
Cc: "php-internals@lists.php.net" php-internals@lists.php.net; "internals@lists.php.net" internals@lists.php.net
Sent: Sunday, May 5, 2013 8:55 AM
Subject: Re: [PHP-DEV] Scalar Type Casting Magic Methods
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
This can't go into PHP 5.5 anymore as we're already past feature freeze.
Nikita
hi!
Thanks for the reply. I hope it would be part of next release eg 5.5.1
More 5.6. Features freeze for 5.5.x.
Cheers,
Pierre
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_typesThe 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
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
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_typesThe 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 soI 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
2013.05.08. 7:38, "Pierre du Plessis" pierre@pcservice.co.za ezt írta:
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
yeah, I also think that ArrayObjects should be accepted where array is
expected.
2013.05.08. 7:38, "Pierre du Plessis" pierre@pcservice.co.za ezt írta:
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
This can't work.
Consider
<?php
class C {
public function __toString() { return "string"; }
public function __toArray() { return []; }
}
$result = str_replace(new C, new C, new C);
?>
Which method will be called?
array functions can accept an object implementing ArrayAccess as well
instead of just an arrayyeah, I also think that ArrayObjects should be accepted where array is
expected.
Patches are certainly welcome, but be sure to get to every place, else
it becomes an inconsistent mess :)
Oh, and be consistent about return values of operations ... oh, and will
$result = some_array_operation(new ArrayObject);
return an array or instance of ArrayObject, if the later how will it be
instantiated ... do we have to pass result factories or something to all
of those?
johannes