bug21961.phpt 860 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. --TEST--
  2. Bug #21961 (get_parent_class() segfault)
  3. --FILE--
  4. <?php
  5. class man
  6. {
  7. public $name, $bars;
  8. function __construct()
  9. {
  10. $this->name = 'Mr. X';
  11. $this->bars = array();
  12. }
  13. function getdrunk($where)
  14. {
  15. $this->bars[] = new bar($where);
  16. }
  17. function getName()
  18. {
  19. return $this->name;
  20. }
  21. }
  22. class bar extends man
  23. {
  24. public $name;
  25. function __construct($w)
  26. {
  27. $this->name = $w;
  28. }
  29. function getName()
  30. {
  31. return $this->name;
  32. }
  33. function whosdrunk()
  34. {
  35. $who = get_parent_class($this);
  36. if($who == NULL)
  37. {
  38. return 'nobody';
  39. }
  40. return eval("return ".$who.'::getName();');
  41. }
  42. }
  43. $x = new man;
  44. $x->getdrunk('The old Tavern');
  45. var_dump($x->bars[0]->whosdrunk());
  46. ?>
  47. --EXPECT--
  48. string(14) "The old Tavern"