|
|
|
| http://ua.php.net/manual/en/migration52.incompatible.php
Changed __toString() to be called wherever applicable. The magic method __toString() will now be called in a string context, that is, anywhere an object is used as a string. The fallback of returning a string that contains the object identifier was dropped in PHP 5.2.0. It became problematic because an object identifier cannot be considered unique. This change will mean that your application is flawed if you have relied on the object identifier as a return value. An attempt to use that value as a string will now result in a catchable fatal error.
<?php
class foo {}
$foo = new foo;
print $foo;
/* Catchable fatal error: Object of class foo could
not be converted to string in filename on line n */
?>
Even with __toString(), objects cannot be used as array indices or keys. We may add built-in hash support for this at a later date, but as of PHP 5.2.x you will need to either provide your own hashing or use the new SPL function spl_object_hash(). Exceptions can not be thrown from __toString() methods.
Не до конца это понял — будет ли нормальная поддержка __toString, или что значит подобное изменение?
Подскажите, пожалуйста! | |
|
|