bug26166.phpt 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. --TEST--
  2. Bug #26166 (__toString() crash when no values returned)
  3. --FILE--
  4. <?php
  5. class Foo
  6. {
  7. function __toString()
  8. {
  9. return "Hello World!\n";
  10. }
  11. }
  12. class Bar
  13. {
  14. private $obj;
  15. function __construct()
  16. {
  17. $this->obj = new Foo();
  18. }
  19. function __toString()
  20. {
  21. return $this->obj->__toString();
  22. }
  23. }
  24. $o = new Bar;
  25. echo $o;
  26. echo "===NONE===\n";
  27. function my_error_handler($errno, $errstr, $errfile, $errline) {
  28. var_dump($errstr);
  29. }
  30. set_error_handler('my_error_handler');
  31. class NoneTest
  32. {
  33. function __toString() {
  34. }
  35. }
  36. $o = new NoneTest;
  37. echo $o;
  38. echo "===THROW===\n";
  39. class ErrorTest
  40. {
  41. function __toString() {
  42. throw new Exception("This is an error!");
  43. }
  44. }
  45. $o = new ErrorTest;
  46. try {
  47. echo $o;
  48. }
  49. catch (Exception $e) {
  50. echo "Got the exception\n";
  51. }
  52. ?>
  53. ===DONE===
  54. --EXPECTF--
  55. Hello World!
  56. ===NONE===
  57. string(%d) "Method NoneTest::__toString() must return a string value"
  58. ===THROW===
  59. Fatal error: Method ErrorTest::__toString() must not throw an exception, caught Exception: This is an error! in %sbug26166.php on line %d