closure_instantiate.phpt 595 B

123456789101112131415161718192021
  1. --TEST--
  2. Closures cannot be instantiated directly
  3. --CREDITS--
  4. Mark Baker mark@lange.demon.co.uk at the PHPNW2017 Conference for PHP Testfest 2017
  5. --FILE--
  6. <?php
  7. try {
  8. // Closures should be instantiatable using new
  9. $x = new Closure();
  10. } catch (Exception $e) {
  11. // Instantiating a closure is an error, not an exception, so we shouldn't see this
  12. echo 'EXCEPTION: ', $e->getMessage();
  13. } catch (Throwable $e) {
  14. // This is the message that we should see for a caught error
  15. echo 'ERROR: ', $e->getMessage();
  16. }
  17. ?>
  18. --EXPECT--
  19. ERROR: Instantiation of class Closure is not allowed