011.phpt 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. --TEST--
  2. property_exists() tests
  3. --FILE--
  4. <?php
  5. class foo {
  6. public $pp1 = 1;
  7. private $pp2 = 2;
  8. protected $pp3 = 3;
  9. function bar() {
  10. var_dump(property_exists("foo","pp1"));
  11. var_dump(property_exists("foo","pp2"));
  12. var_dump(property_exists("foo","pp3"));
  13. }
  14. }
  15. class bar extends foo {
  16. function test() {
  17. var_dump(property_exists("foo","pp1"));
  18. var_dump(property_exists("foo","pp2"));
  19. var_dump(property_exists("foo","pp3"));
  20. }
  21. }
  22. var_dump(property_exists("foo","pp1"));
  23. var_dump(property_exists("foo","pp2"));
  24. var_dump(property_exists("foo","pp3"));
  25. var_dump(property_exists("foo","nonexistent"));
  26. var_dump(property_exists("fo","nonexistent"));
  27. var_dump(property_exists("foo",""));
  28. var_dump(property_exists("","test"));
  29. var_dump(property_exists("",""));
  30. $foo = new foo;
  31. var_dump(property_exists($foo,"pp1"));
  32. var_dump(property_exists($foo,"pp2"));
  33. var_dump(property_exists($foo,"pp3"));
  34. var_dump(property_exists($foo,"nonexistent"));
  35. var_dump(property_exists($foo,""));
  36. try {
  37. var_dump(property_exists(array(), "test"));
  38. } catch (\TypeError $e) {
  39. echo $e->getMessage() . \PHP_EOL;
  40. }
  41. try {
  42. var_dump(property_exists(1, "test"));
  43. } catch (\TypeError $e) {
  44. echo $e->getMessage() . \PHP_EOL;
  45. }
  46. try {
  47. var_dump(property_exists(3.14, "test"));
  48. } catch (\TypeError $e) {
  49. echo $e->getMessage() . \PHP_EOL;
  50. }
  51. try {
  52. var_dump(property_exists(true, "test"));
  53. } catch (\TypeError $e) {
  54. echo $e->getMessage() . \PHP_EOL;
  55. }
  56. try {
  57. var_dump(property_exists(null, "test"));
  58. } catch (\TypeError $e) {
  59. echo $e->getMessage() . \PHP_EOL;
  60. }
  61. $foo->bar();
  62. $bar = new bar;
  63. $bar->test();
  64. ?>
  65. --EXPECT--
  66. bool(true)
  67. bool(true)
  68. bool(true)
  69. bool(false)
  70. bool(false)
  71. bool(false)
  72. bool(false)
  73. bool(false)
  74. bool(true)
  75. bool(true)
  76. bool(true)
  77. bool(false)
  78. bool(false)
  79. property_exists(): Argument #1 ($object_or_class) must be of type object|string, array given
  80. property_exists(): Argument #1 ($object_or_class) must be of type object|string, int given
  81. property_exists(): Argument #1 ($object_or_class) must be of type object|string, float given
  82. property_exists(): Argument #1 ($object_or_class) must be of type object|string, bool given
  83. property_exists(): Argument #1 ($object_or_class) must be of type object|string, null given
  84. bool(true)
  85. bool(true)
  86. bool(true)
  87. bool(true)
  88. bool(true)
  89. bool(true)