1--TEST-- 2Bug #26166 (__toString() crash when no values returned) 3--FILE-- 4<?php 5 6class Foo 7{ 8 function __toString() 9 { 10 return "Hello World!\n"; 11 } 12} 13 14class Bar 15{ 16 private $obj; 17 18 function __construct() 19 { 20 $this->obj = new Foo(); 21 } 22 23 function __toString() 24 { 25 return $this->obj->__toString(); 26 } 27} 28 29$o = new Bar; 30echo $o; 31 32echo "===NONE===\n"; 33 34class NoneTest 35{ 36 function __toString() { 37 } 38} 39 40$o = new NoneTest; 41try { 42 echo $o; 43} catch (Error $e) { 44 echo $e->getMessage(), "\n"; 45} 46 47echo "===THROW===\n"; 48 49class ErrorTest 50{ 51 function __toString() { 52 throw new Exception("This is an error!"); 53 } 54} 55 56$o = new ErrorTest; 57try { 58 echo $o; 59} catch (Exception $e) { 60 echo $e->getMessage(), "\n"; 61} 62 63?> 64===DONE=== 65--EXPECT-- 66Hello World! 67===NONE=== 68Method NoneTest::__toString() must return a string value 69===THROW=== 70This is an error! 71===DONE=== 72