2003-11-08 22:06:08 +08:00
|
|
|
--TEST--
|
2003-12-23 06:50:02 +08:00
|
|
|
Bug #26166 (__toString() crash when no values returned)
|
2003-11-08 22:06:08 +08:00
|
|
|
--FILE--
|
|
|
|
<?php
|
2006-05-11 06:46:16 +08:00
|
|
|
|
2003-11-08 22:06:08 +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";
|
|
|
|
|
2015-05-17 05:49:14 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-05-17 05:49:14 +08:00
|
|
|
$o = new NoneTest;
|
2019-02-26 22:32:18 +08:00
|
|
|
try {
|
|
|
|
echo $o;
|
|
|
|
} catch (Error $e) {
|
|
|
|
echo $e->getMessage(), "\n";
|
|
|
|
}
|
2006-05-11 06:46:16 +08:00
|
|
|
|
2003-11-08 22:06:08 +08:00
|
|
|
echo "===THROW===\n";
|
|
|
|
|
2015-05-17 05:49:14 +08:00
|
|
|
class ErrorTest
|
2003-11-08 22:06:08 +08:00
|
|
|
{
|
2020-02-04 05:52:20 +08:00
|
|
|
function __toString() {
|
|
|
|
throw new Exception("This is an error!");
|
|
|
|
}
|
2003-11-08 22:06:08 +08:00
|
|
|
}
|
|
|
|
|
2015-05-17 05:49:14 +08:00
|
|
|
$o = new ErrorTest;
|
2003-11-08 22:06:08 +08:00
|
|
|
try {
|
2020-02-04 05:52:20 +08:00
|
|
|
echo $o;
|
2019-02-26 22:32:18 +08:00
|
|
|
} catch (Exception $e) {
|
2020-02-04 05:52:20 +08:00
|
|
|
echo $e->getMessage(), "\n";
|
2003-11-08 22:06:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|
2019-02-26 22:32:18 +08:00
|
|
|
--EXPECT--
|
2003-11-08 22:06:08 +08:00
|
|
|
Hello World!
|
|
|
|
===NONE===
|
2020-05-26 01:28:15 +08:00
|
|
|
NoneTest::__toString(): Return value must be of type string, none returned
|
2006-05-11 06:46:16 +08:00
|
|
|
===THROW===
|
2019-02-26 22:32:18 +08:00
|
|
|
This is an error!
|