|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-08-05 00:04 UTC] tony2001@php.net
[2005-08-05 11:02 UTC] dmitry@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 19:00:01 2025 UTC |
Description: ------------ When attempting to cast an object to an int, it remains untouched. No warnings or errors are displayed. The results are the same for (int), intval(), and settype(). float, bool, string, and array all seem to work correctly. I get the same results in both 5.0.3 and 5.1.0b3. In 4.3.11, an object can be cast to int. Reproduce code: --------------- <?php error_reporting(E_ALL); class Foo { var $bar = "bat"; } $foo = new Foo; var_dump($foo); $bar = (int)$foo; var_dump($bar); $baz = (float)$foo; var_dump($baz); ?> Expected result: ---------------- object(Foo)#1 (1) { ["bar"]=> string(3) "bat" } int(1) float(1) Actual result: -------------- object(Foo)#1 (1) { ["bar"]=> string(3) "bat" } object(Foo)#1 (1) { ["bar"]=> string(3) "bat" } Notice: Object of class Foo could not be converted to double in /home/crywolf/Test/cast_object.php on line 14 float(1)