xref: /PHP-5.5/Zend/tests/bug26166.phpt (revision 610c7fbe)
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
34function my_error_handler($errno, $errstr, $errfile, $errline) {
35	var_dump($errstr);
36}
37
38set_error_handler('my_error_handler');
39
40class None
41{
42	function __toString() {
43	}
44}
45
46$o = new None;
47echo $o;
48
49echo "===THROW===\n";
50
51class Error
52{
53	function __toString() {
54		throw new Exception("This is an error!");
55	}
56}
57
58$o = new Error;
59try {
60	echo $o;
61}
62catch (Exception $e) {
63	echo "Got the exception\n";
64}
65
66?>
67===DONE===
68--EXPECTF--
69Hello World!
70===NONE===
71string(52) "Method None::__toString() must return a string value"
72===THROW===
73
74Fatal error: Method Error::__toString() must not throw an exception in %sbug26166.php on line %d
75