On Wed, Feb 25, 2015 at 7:29 AM, Dmitry Stogov <dmi...@zend.com> wrote: > On Wed, Feb 25, 2015 at 6:09 PM, Anthony Ferrara <ircmax...@gmail.com> > wrote: > >> Dmitry, >> >> > The object on the call-site should remain to be an object (if it's not >> > passed by reference), however the called function will receive a string. >> > It works in PHP-5 and PHP-7. Nothing should be changed. >> > >> > $ sapi/cli/php -r 'class X {function __toString(){return "abc";}} $x=new >> X; >> > var_dump(strlen($x)); var_dump($x);' >> > int(3) >> > object(X)#1 (0) { >> > } >> > >> > However, declare(strict_types=1) will break this. see >> > >> https://github.com/ircmaxell/php-src/compare/scalar_type_hints_v5#diff-ef5bf53d1412b50f85d125ca4fe84741R1182 >> >> "Break" is a loaded term. >> > > OK. it's a BC break. > What is the reason for __toString() if it's not going to be called. > > >> >> It's intentionally not calling __toString, because that's not only a >> cast (like "5" -> int(5)), but it's a lossy cast (like 5.5 -> int(5) >> or "5 apples" => int(5)). >> > > this is about conversion rules that may be safe or not. > > >> One point of strict mode is that it's there intentionally to turn off >> magic. It's there to make things explicit, predictable and robust. >> > > turn off magic to get what? Need to write explicit (int) or (string)? > We have a number of such patterns that hide errors even in PHP sources (in > C).
Right, we do. And we should somehow treat warnings like that as error, in C :) That being said (and totally OT), changing casting rules and adding yet another set of magic rules is better? I agree to totally disagree here. I will never agree on changing these rules (or maybe in php12). Cheers, -- Pierre @pierrejoye | http://www.libgd.org -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php