xref: /php-src/Zend/tests/bug26166.phpt (revision fbe30592)
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--EXPECT--
65Hello World!
66===NONE===
67NoneTest::__toString(): Return value must be of type string, none returned
68===THROW===
69This is an error!
70