com php-src: Test nested strict/weak function calls: Zend/tests/typehints/strict_nested.phpt
| From: | Dmitry Stogov | Date: | Tue, 10 Feb 2015 15:48:08 +0000 |
| Subject: | com php-src: Test nested strict/weak function calls: Zend/tests/typehints/strict_nested.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-85719@lists.php.net to get a copy of this message | ||
Commit: 187a95f8d3a9f482b30c3b382d6ee4de356e6c5c
Author: Andrea Faulds <ajf@ajf.me> Sun, 25 Jan 2015 03:06:45 +0000
Parents: c6e804813808c5e812a31d3bf177c73a104c59cd
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=187a95f8d3a9f482b30c3b382d6ee4de356e6c5c
Log:
Test nested strict/weak function calls
Changed paths:
A Zend/tests/typehints/strict_nested.phpt
Diff:
diff --git a/Zend/tests/typehints/strict_nested.phpt b/Zend/tests/typehints/strict_nested.phpt
new file mode 100644
index 0000000..44e5214
--- /dev/null
+++ b/Zend/tests/typehints/strict_nested.phpt
@@ -0,0 +1,115 @@
+--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
+(new StrictTakesIntCaller)->call(); // should cause an error
+(new WeakTakesIntCaller)->call(); // should succeed
+(new ExplicitWeakTakesIntCaller)->call(); // 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
+ (new StrictTakesIntCaller)->call(); // should cause an error
+ (new WeakTakesIntCaller)->call(); // should succeed
+ (new ExplicitWeakTakesIntCaller)->call(); // 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
+ (new StrictTakesIntCaller)->call(); // should cause an error
+ (new WeakTakesIntCaller)->call(); // should succeed
+ (new ExplicitWeakTakesIntCaller)->call(); // 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 31 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 31 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 31 and defined in %sstrict_nested.php on line 14
+Failure!
+Success!
+Success!