bug31098.phpt 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. --TEST--
  2. Bug #31098 (isset() / empty() incorrectly returns true in dereference of a wrong type)
  3. --FILE--
  4. <?php
  5. $a = '';
  6. var_dump(isset($a->b));
  7. $a = 'a';
  8. var_dump(isset($a->b));
  9. $a = '0';
  10. var_dump(isset($a->b));
  11. $a = '';
  12. var_dump(isset($a['b']));
  13. $a = 'a';
  14. var_dump(isset($a['b']));
  15. $a = '0';
  16. var_dump(isset($a['b']));
  17. $simpleString = "Bogus String Text";
  18. echo isset($simpleString->wrong)?"bug\n":"ok\n";
  19. try {
  20. echo isset($simpleString["wrong"])?"bug\n":"ok\n";
  21. } catch (\TypeError $e) {
  22. echo $e->getMessage() . \PHP_EOL;
  23. }
  24. echo isset($simpleString[-20])?"bug\n":"ok\n";
  25. echo isset($simpleString[0])?"ok\n":"bug\n";
  26. echo isset($simpleString["0"])?"ok\n":"bug\n";
  27. echo isset($simpleString["16"])?"ok\n":"bug\n";
  28. echo isset($simpleString["17"])?"bug\n":"ok\n";
  29. echo $simpleString->wrong === null?"ok\n":"bug\n";
  30. try {
  31. echo $simpleString["wrong"] === "B"?"ok\n":"bug\n";
  32. } catch (\TypeError $e) {
  33. echo $e->getMessage() . \PHP_EOL;
  34. }
  35. echo $simpleString["0"] === "B"?"ok\n":"bug\n";
  36. try {
  37. /* This must not affect the string value */
  38. $simpleString["wrong"] = "f";
  39. } catch (\TypeError $e) {
  40. echo $e->getMessage() . \PHP_EOL;
  41. }
  42. echo $simpleString["0"] === "B"?"ok\n":"bug\n";
  43. ?>
  44. --EXPECTF--
  45. bool(false)
  46. bool(false)
  47. bool(false)
  48. bool(false)
  49. bool(false)
  50. bool(false)
  51. ok
  52. ok
  53. ok
  54. ok
  55. ok
  56. ok
  57. ok
  58. Warning: Attempt to read property "wrong" on string in %s on line %d
  59. ok
  60. Cannot access offset of type string on string
  61. ok
  62. Cannot access offset of type string on string
  63. ok