bug26166.phpt 918 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. class NoneTest
  28. {
  29. function __toString() {
  30. }
  31. }
  32. $o = new NoneTest;
  33. try {
  34. echo $o;
  35. } catch (Error $e) {
  36. echo $e->getMessage(), "\n";
  37. }
  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. } catch (Exception $e) {
  49. echo $e->getMessage(), "\n";
  50. }
  51. ?>
  52. --EXPECT--
  53. Hello World!
  54. ===NONE===
  55. NoneTest::__toString(): Return value must be of type string, none returned
  56. ===THROW===
  57. This is an error!