forked from php/php-src
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test nested strict/weak function calls
- Loading branch information
1 parent
8c830b1
commit 403c887
Showing
1 changed file
with
94 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
--TEST-- | ||
Test nested function calls in strict_types=0 and strict_types=1 modes | ||
--FILE-- | ||
<?php | ||
|
||
$errored = FALSE; | ||
|
||
set_error_handler(function (int $errno, string $errstr, string $errfile, int $errline) use (&$errored) { | ||
// skipping errors make testing more practical | ||
if ($errno !== E_RECOVERABLE_ERROR) die("Wrong errno"); | ||
|
||
echo "Catchable fatal error: $errstr in $errfile on line $errline\n"; | ||
$errored = TRUE; | ||
return TRUE; | ||
}); | ||
|
||
function takes_int(int $x) { | ||
global $errored; | ||
if ($errored) { | ||
echo "Failure!", PHP_EOL; | ||
$errored = FALSE; | ||
} else { | ||
echo "Success!", PHP_EOL; | ||
} | ||
} | ||
|
||
declare(strict_types=1) { | ||
function strict_calls_takes_int() { | ||
takes_int(1.0); // should fail, strict mode | ||
} | ||
|
||
class StrictTakesIntCaller { | ||
public function call() { | ||
takes_int(1.0); // should fail, strict mode | ||
} | ||
} | ||
} | ||
|
||
declare(strict_types=0) { | ||
function explicit_weak_calls_takes_int() { | ||
takes_int(1.0); // should succeed, weak mode | ||
} | ||
|
||
class ExplicitWeakTakesIntCaller { | ||
public function call() { | ||
takes_int(1.0); // should succeed, weak mode | ||
} | ||
} | ||
} | ||
|
||
// implicit weak mode code | ||
function weak_calls_takes_int() { | ||
takes_int(1.0); // should succeed, weak mode | ||
} | ||
|
||
class WeakTakesIntCaller { | ||
public function call() { | ||
takes_int(1.0); // should succeed, weak mode | ||
} | ||
} | ||
|
||
// Now for the calling! | ||
|
||
// implicit weak mode code | ||
strict_calls_takes_int(); // should cause an error: our call to func is weak, but it was declared in strict mode so calls it makes are strict | ||
weak_calls_takes_int(); // should succeed | ||
explicit_weak_calls_takes_int(); // should succeed | ||
|
||
declare(strict_types=0) { | ||
strict_calls_takes_int(); // should cause an error: our call to func is weak, but it was declared in strict mode so calls it makes are strict | ||
weak_calls_takes_int(); // should succeed | ||
explicit_weak_calls_takes_int(); // should succeed | ||
} | ||
|
||
declare(strict_types=1) { | ||
strict_calls_takes_int(); // should cause an error | ||
weak_calls_takes_int(); // should succeed: our call to func is strict, but it was declared in weak mode so calls it makes are weak | ||
explicit_weak_calls_takes_int(); // should succeed | ||
} | ||
|
||
?> | ||
--EXPECTF-- | ||
Catchable fatal error: Argument 1 passed to takes_int() must be of the type integer, float given, called in %sstrict_nested.php on line 26 and defined in %sstrict_nested.php on line 14 | ||
Failure! | ||
Success! | ||
Success! | ||
Catchable fatal error: Argument 1 passed to takes_int() must be of the type integer, float given, called in %sstrict_nested.php on line 26 and defined in %sstrict_nested.php on line 14 | ||
Failure! | ||
Success! | ||
Success! | ||
Catchable fatal error: Argument 1 passed to takes_int() must be of the type integer, float given, called in %sstrict_nested.php on line 26 and defined in %sstrict_nested.php on line 14 | ||
Failure! | ||
Success! | ||
Success! |