Skip to content

Commit c5f9855

Browse files
MarkBakerpetk
authored andcommitted
Test to verify that closures can't be instantiated
1 parent d22dd5f commit c5f9855

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Closures cannot be instantiated directly
3+
--CREDITS--
4+
Mark Baker [email protected] at the PHPNW2017 Conference for PHP Testfest 2017
5+
--FILE--
6+
<?php
7+
8+
try {
9+
// Closures should be instantiatable using new
10+
$x = new Closure();
11+
} catch (Exception $e) {
12+
// Instantiating a closure is an error, not an exception, so we shouldn't see this
13+
echo 'EXCEPTION: ', $e->getMessage();
14+
} catch (Throwable $e) {
15+
// This is the mesage that we should see for a caught error
16+
echo 'ERROR: ', $e->getMessage();
17+
}
18+
19+
?>
20+
--EXPECT--
21+
ERROR: Instantiation of 'Closure' is not allowed

0 commit comments

Comments
 (0)