--TEST-- ZE2 __toString() --FILE-- getMessage(), "\n"; } var_dump($o); echo "====test2====\n"; $o = new test2; print_r($o); print $o; var_dump($o); echo "====test3====\n"; echo $o; echo "====test4====\n"; echo "string:".$o; echo "====test5====\n"; echo 1 . $o; echo 1 , $o; echo "====test6====\n"; echo $o . $o; echo $o , $o; echo "====test7====\n"; $ar = array(); $ar[$o->__toString()] = "ERROR"; try { echo $ar[$o]; } catch (Error $e) { echo $e->getMessage(), "\n"; } echo "====test8====\n"; var_dump(trim($o)); var_dump(trim((string)$o)); echo "====test9====\n"; echo sprintf("%s", $o); echo "====test10====\n"; $o = new test3; var_dump($o); try { echo $o; } catch (Error $e) { echo $e->getMessage(), "\n"; } ?> ====DONE==== --EXPECT-- ====test1==== test1 Object ( ) Object of class test1 could not be converted to string object(test1)#1 (0) { } ====test2==== test2 Object ( ) test2::__toString() Converted object(test2)#3 (0) { } ====test3==== test2::__toString() Converted ====test4==== test2::__toString() string:Converted ====test5==== test2::__toString() 1Converted 1test2::__toString() Converted ====test6==== test2::__toString() test2::__toString() Converted Converted test2::__toString() Converted test2::__toString() Converted ====test7==== test2::__toString() Cannot access offset of type test2 on array ====test8==== test2::__toString() string(9) "Converted" test2::__toString() string(9) "Converted" ====test9==== test2::__toString() Converted ====test10==== object(test3)#2 (0) { } test3::__toString() test3::__toString(): Return value must be of type string, array returned ====DONE====