|
| 1 | +--TEST-- |
| 2 | +Calling class_exists() on Enums should trigger a deprecation |
| 3 | +--DESCRIPTION-- |
| 4 | +Calling class_exists() on Enums is deprecated, but it should continue to return |
| 5 | +the correct result. The underlying functionality for (class|trait|enum|interface)_exists |
| 6 | +is shared, so this deprecation should only affect class_exists() function and no |
| 7 | +other functions. |
| 8 | +--FILE-- |
| 9 | +<?php |
| 10 | + |
| 11 | +enum Foo { |
| 12 | + case Bar; |
| 13 | +} |
| 14 | + |
| 15 | +class Bar { |
| 16 | + |
| 17 | +} |
| 18 | + |
| 19 | +spl_autoload_register(function ($className) { |
| 20 | + echo "Triggered autoloader with Enum $className\n"; |
| 21 | + |
| 22 | + if ($className === 'Quux') { |
| 23 | + enum Quux {} |
| 24 | + } |
| 25 | +}); |
| 26 | + |
| 27 | +echo "Testing: Foo"; |
| 28 | +var_dump(class_exists('Foo')); |
| 29 | +var_dump(enum_exists('Foo')); |
| 30 | + |
| 31 | +echo "Testing: Bar\n"; |
| 32 | +var_dump(class_exists('Bar')); |
| 33 | +var_dump(!enum_exists('Bar')); |
| 34 | +var_dump(!enum_exists('Bar', true)); |
| 35 | + |
| 36 | +echo "Testing: Quux\n"; |
| 37 | +var_dump(!class_exists('Quux', false)); |
| 38 | +var_dump(class_exists('Quux', true)); |
| 39 | +var_dump(class_exists('Quux', true)); |
| 40 | +var_dump(enum_exists('Quux', true)); |
| 41 | + |
| 42 | +echo "trait_exists() and interface_exists()\n"; |
| 43 | +var_dump(!trait_exists('Foo')); |
| 44 | +var_dump(!trait_exists('Bar')); |
| 45 | +var_dump(!trait_exists('Quux')); |
| 46 | +var_dump(!interface_exists('Foo')); |
| 47 | +var_dump(!interface_exists('Bar')); |
| 48 | +var_dump(!interface_exists('Quux')); |
| 49 | +?> |
| 50 | +--EXPECTF-- |
| 51 | +Testing: Foo |
| 52 | +Deprecated: using class_exists() for enums is deprecated, triggerred for calling class_exists() for enum "Foo". Use enum_exists() instead %s on line %d |
| 53 | +bool(true) |
| 54 | +bool(true) |
| 55 | +Testing: Bar |
| 56 | +bool(true) |
| 57 | +bool(true) |
| 58 | +bool(true) |
| 59 | +Testing: Quux |
| 60 | +bool(true) |
| 61 | +Triggered autoloader with Enum Quux |
| 62 | + |
| 63 | +Deprecated: using class_exists() for enums is deprecated, triggerred for calling class_exists() for enum "Quux". Use enum_exists() instead %s on line %d |
| 64 | +bool(true) |
| 65 | + |
| 66 | +Deprecated: using class_exists() for enums is deprecated, triggerred for calling class_exists() for enum "Quux". Use enum_exists() instead %s on line %d |
| 67 | +bool(true) |
| 68 | +bool(true) |
| 69 | +trait_exists() and interface_exists() |
| 70 | +bool(true) |
| 71 | +bool(true) |
| 72 | +bool(true) |
| 73 | +bool(true) |
| 74 | +bool(true) |
| 75 | +bool(true) |
0 commit comments