php-src/Zend/tests/bug26166.phpt

70 lines
918 B
Plaintext
Raw Normal View History

--TEST--
Bug #26166 (__toString() crash when no values returned)
--FILE--
<?php
2006-05-11 06:46:16 +08:00
class Foo
{
function __toString()
{
return "Hello World!\n";
}
}
class Bar
{
private $obj;
function __construct()
{
$this->obj = new Foo();
}
function __toString()
{
return $this->obj->__toString();
}
}
$o = new Bar;
echo $o;
2006-05-11 06:46:16 +08:00
echo "===NONE===\n";
class NoneTest
2006-05-11 06:46:16 +08:00
{
2020-02-04 05:52:20 +08:00
function __toString() {
}
2006-05-11 06:46:16 +08:00
}
$o = new NoneTest;
try {
echo $o;
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
2006-05-11 06:46:16 +08:00
echo "===THROW===\n";
class ErrorTest
{
2020-02-04 05:52:20 +08:00
function __toString() {
throw new Exception("This is an error!");
}
}
$o = new ErrorTest;
try {
2020-02-04 05:52:20 +08:00
echo $o;
} catch (Exception $e) {
2020-02-04 05:52:20 +08:00
echo $e->getMessage(), "\n";
}
?>
--EXPECT--
Hello World!
===NONE===
NoneTest::__toString(): Return value must be of type string, none returned
2006-05-11 06:46:16 +08:00
===THROW===
This is an error!