-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
471 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--TEST-- | ||
Can define die and exit as class methods, constants and property | ||
--FILE-- | ||
<?php | ||
|
||
class Foo { | ||
public $exit; | ||
public $die; | ||
|
||
const die = 5; | ||
const exit = 10; | ||
|
||
public function exit() { | ||
return 20; | ||
} | ||
|
||
public function die() { | ||
return 15; | ||
} | ||
} | ||
|
||
var_dump(Foo::die); | ||
var_dump(Foo::exit); | ||
$o = new Foo(); | ||
var_dump($o->exit); | ||
var_dump($o->die); | ||
var_dump($o->exit()); | ||
var_dump($o->die()); | ||
|
||
?> | ||
--EXPECT-- | ||
int(5) | ||
int(10) | ||
NULL | ||
NULL | ||
int(20) | ||
int(15) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--TEST-- | ||
Attempting to define die constant | ||
--FILE-- | ||
<?php | ||
|
||
const die = 5; | ||
|
||
var_dump(die); | ||
|
||
?> | ||
--EXPECTF-- | ||
Parse error: syntax error, unexpected token "exit", expecting identifier in %s on line %d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--TEST-- | ||
Attempting to define die constant in a namespace | ||
--FILE-- | ||
<?php | ||
|
||
namespace Foo; | ||
|
||
const die = 5; | ||
|
||
var_dump(die); | ||
|
||
?> | ||
--EXPECTF-- | ||
Parse error: syntax error, unexpected token "exit", expecting identifier in %s on line %d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--TEST-- | ||
Attempting to define die() function | ||
--FILE-- | ||
<?php | ||
|
||
function die() { } | ||
|
||
?> | ||
--EXPECTF-- | ||
Parse error: syntax error, unexpected token "exit", expecting "(" in %s on line %d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--TEST-- | ||
Attempting to define die() function in a namespace | ||
--FILE-- | ||
<?php | ||
|
||
namespace Foo; | ||
|
||
function die() { } | ||
|
||
var_dump(die()); | ||
|
||
?> | ||
--EXPECTF-- | ||
Parse error: syntax error, unexpected token "exit", expecting "(" in %s on line %d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--TEST-- | ||
Attempting to define exit constant | ||
--FILE-- | ||
<?php | ||
|
||
const exit = 5; | ||
|
||
var_dump(exit); | ||
|
||
?> | ||
--EXPECTF-- | ||
Parse error: syntax error, unexpected token "exit", expecting identifier in %s on line %d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--TEST-- | ||
Attempting to define exit constant in a namespace | ||
--FILE-- | ||
<?php | ||
|
||
namespace Foo; | ||
|
||
const exit = 5; | ||
|
||
var_dump(exit); | ||
|
||
?> | ||
--EXPECTF-- | ||
Parse error: syntax error, unexpected token "exit", expecting identifier in %s on line %d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--TEST-- | ||
Attempting to define exit() function | ||
--FILE-- | ||
<?php | ||
|
||
function exit() { } | ||
|
||
?> | ||
--EXPECTF-- | ||
Parse error: syntax error, unexpected token "exit", expecting "(" in %s on line %d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--TEST-- | ||
Attempting to define exit() function in a namespace | ||
--FILE-- | ||
<?php | ||
|
||
namespace Foo; | ||
|
||
function exit() { } | ||
|
||
?> | ||
--EXPECTF-- | ||
Parse error: syntax error, unexpected token "exit", expecting "(" in %s on line %d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--TEST-- | ||
Attempting to define a goto label called die | ||
--FILE-- | ||
<?php | ||
|
||
echo "Before\n"; | ||
|
||
echo "In between\n"; | ||
die: | ||
echo "After\n"; | ||
|
||
?> | ||
--EXPECTF-- | ||
Parse error: syntax error, unexpected token ":" in %s on line %d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--TEST-- | ||
Attempting to define a goto label called die and jump to it | ||
--FILE-- | ||
<?php | ||
|
||
echo "Before\n"; | ||
goto die; | ||
echo "In between\n"; | ||
die: | ||
echo "After\n"; | ||
|
||
?> | ||
--EXPECTF-- | ||
Parse error: syntax error, unexpected token "exit", expecting identifier in %s on line %d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--TEST-- | ||
Attempting to define a goto label called exit | ||
--FILE-- | ||
<?php | ||
|
||
echo "Before\n"; | ||
|
||
echo "In between\n"; | ||
exit: | ||
echo "After\n"; | ||
|
||
?> | ||
--EXPECTF-- | ||
Parse error: syntax error, unexpected token ":" in %s on line %d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--TEST-- | ||
Attempting to define a goto label called exit and jump to it | ||
--FILE-- | ||
<?php | ||
|
||
echo "Before\n"; | ||
goto exit; | ||
echo "In between\n"; | ||
exit: | ||
echo "After\n"; | ||
|
||
?> | ||
--EXPECTF-- | ||
Parse error: syntax error, unexpected token "exit", expecting identifier in %s on line %d |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--TEST-- | ||
Using disable_functions INI to remove die | ||
--INI-- | ||
disable_functions=die | ||
--FILE-- | ||
<?php | ||
|
||
die(); | ||
|
||
?> | ||
--EXPECT-- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--TEST-- | ||
Using disable_functions INI to remove exit | ||
--INI-- | ||
disable_functions=exit | ||
--FILE-- | ||
<?php | ||
|
||
exit(); | ||
|
||
?> | ||
--EXPECT-- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--TEST-- | ||
exit() as function | ||
--FILE-- | ||
<?php | ||
|
||
function foo(callable $fn) { | ||
var_dump($fn); | ||
} | ||
|
||
$values = [ | ||
'exit', | ||
'die', | ||
exit(...), | ||
die(...), | ||
]; | ||
|
||
foreach ($values as $value) { | ||
foo($value); | ||
} | ||
|
||
?> | ||
--EXPECTF-- | ||
Parse error: syntax error, unexpected token "...", expecting ")" in %s on line %d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--TEST-- | ||
Using exit/die as a statement/constant | ||
--FILE-- | ||
<?php | ||
|
||
const FILE_PATH = __DIR__ . '/exit_statements.inc'; | ||
const FILE_CONTENT = <<<'TEMPLATE' | ||
<?php | ||
echo "Before FUNCTION"; | ||
try { | ||
FUNCTION; | ||
} catch (\Throwable $e) { | ||
echo $e::class, ': ', $e->getMessage(), PHP_EOL; | ||
} | ||
|
||
TEMPLATE; | ||
|
||
|
||
$php = getenv('TEST_PHP_EXECUTABLE_ESCAPED'); | ||
$command = $php . ' ' . escapeshellarg(FILE_PATH); | ||
|
||
foreach (['exit', 'die'] as $value) { | ||
echo 'Using ', $value, ' as value:', PHP_EOL; | ||
$output = []; | ||
$content = str_replace('FUNCTION', $value, FILE_CONTENT); | ||
file_put_contents(FILE_PATH, $content); | ||
exec($command, $output, $exit_status); | ||
echo 'Exit status is: ', $exit_status, PHP_EOL, | ||
'Output is:', PHP_EOL, join($output), PHP_EOL; | ||
} | ||
|
||
?> | ||
--CLEAN-- | ||
<?php | ||
const FILE_PATH = __DIR__ . '/exit_statements.inc'; | ||
@unlink(FILE_PATH); | ||
?> | ||
--EXPECT-- | ||
Using exit as value: | ||
Exit status is: 0 | ||
Output is: | ||
Before exit | ||
Using die as value: | ||
Exit status is: 0 | ||
Output is: | ||
Before die |
Oops, something went wrong.