Test strict code calling weak code and vice-versa

This commit is contained in:
Andrea Faulds 2015-01-25 02:18:58 +00:00
parent e1a238670c
commit b112c13a41
7 changed files with 87 additions and 0 deletions

View file

@ -0,0 +1,17 @@
--TEST--
strict_types=1 code calling strict_types=0 code
--FILE--
<?php
declare(strict_types=1);
// file that's implicitly weak
require 'strict_call_weak_2.inc';
// Will succeed: Function was declared in weak mode, but that does not matter
// This file uses strict mode, so the call is strict, and float denied for int
function_declared_in_weak_mode(1.0);
?>
--EXPECTF--
Catchable fatal error: Argument 1 passed to function_declared_in_weak_mode() must be of the type integer, float given, called in %sstrict_call_weak.php on line 10 and defined in %sstrict_call_weak_2.inc on line 5

View file

@ -0,0 +1,7 @@
<?php
// implicitly weak code
function function_declared_in_weak_mode(int $x) {
echo "Success!";
}

View file

@ -0,0 +1,17 @@
--TEST--
strict_types=1 code calling explicitly strict_types=0 code
--FILE--
<?php
declare(strict_types=1);
// file that's explicitly weak
require 'strict_call_weak_explicit_2.inc';
// Will succeed: Function was declared in weak mode, but that does not matter
// This file uses strict mode, so the call is strict, and float denied for int
function_declared_in_weak_mode(1.0);
?>
--EXPECTF--
Catchable fatal error: Argument 1 passed to function_declared_in_weak_mode() must be of the type integer, float given, called in %sstrict_call_weak_explicit.php on line 10 and defined in %sstrict_call_weak_explicit_2.inc on line 5

View file

@ -0,0 +1,7 @@
<?php
declare(strict_types=0);
function function_declared_in_weak_mode(int $x) {
echo "Success!";
}

View file

@ -0,0 +1,16 @@
--TEST--
strict_types=0 code calling strict_types=1 code
--FILE--
<?php
// implicitly strict_types=0
// file with strict_types=1
require 'weak_call_strict_2.inc';
// Will succeed: Function was declared in strict mode, but that does not matter
// This file uses weak mode, so the call is weak, and float accepted for int
function_declared_in_strict_mode(1.0);
?>
--EXPECT--
Success!

View file

@ -0,0 +1,7 @@
<?php
declare(strict_types=1);
function function_declared_in_strict_mode(int $x) {
echo "Success!";
}

View file

@ -0,0 +1,16 @@
--TEST--
Explicitly strict_types=0 code calling strict_types=1 code
--FILE--
<?php
declare(strict_types=0);
// file with strict_types=1
require 'weak_call_strict_2.inc';
// Will succeed: Function was declared in strict mode, but that does not matter
// This file uses weak mode, so the call is weak, and float accepted for int
function_declared_in_strict_mode(1.0);
?>
--EXPECT--
Success!