bug24658.phpt 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. --TEST--
  2. Bug #24658 (combo of typehint / reference causes crash)
  3. --FILE--
  4. <?php
  5. class foo {}
  6. function no_typehint($a) {
  7. var_dump($a);
  8. }
  9. function typehint(foo $a) {
  10. var_dump($a);
  11. }
  12. function no_typehint_ref(&$a) {
  13. var_dump($a);
  14. }
  15. function typehint_ref(foo &$a) {
  16. var_dump($a);
  17. }
  18. $v = new foo();
  19. $a = array(new foo(), 1, 2);
  20. no_typehint($v);
  21. typehint($v);
  22. no_typehint_ref($v);
  23. typehint_ref($v);
  24. echo "===no_typehint===\n";
  25. array_walk($a, 'no_typehint');
  26. echo "===no_typehint_ref===\n";
  27. array_walk($a, 'no_typehint_ref');
  28. echo "===typehint===\n";
  29. array_walk($a, 'typehint');
  30. echo "===typehint_ref===\n";
  31. array_walk($a, 'typehint_ref');
  32. ?>
  33. --EXPECTF--
  34. object(foo)#%d (0) {
  35. }
  36. object(foo)#%d (0) {
  37. }
  38. object(foo)#%d (0) {
  39. }
  40. object(foo)#%d (0) {
  41. }
  42. ===no_typehint===
  43. object(foo)#%d (0) {
  44. }
  45. int(1)
  46. int(2)
  47. ===no_typehint_ref===
  48. object(foo)#%d (0) {
  49. }
  50. int(1)
  51. int(2)
  52. ===typehint===
  53. object(foo)#%d (0) {
  54. }
  55. Fatal error: Uncaught TypeError: typehint(): Argument #1 ($a) must be of type foo, int given in %s:%d
  56. Stack trace:
  57. #0 [internal function]: typehint(1, 1)
  58. #1 %s(%d): array_walk(Array, 'typehint')
  59. #2 {main}
  60. thrown in %s on line %d