mirror of
https://github.com/php/php-src.git
synced 2024-09-21 09:57:23 +00:00
Merge branch 'PHP-7.0'
* PHP-7.0: Remove mentions of "type hint" and "typehint"
This commit is contained in:
commit
7a2f60d3c7
@ -1,5 +1,5 @@
|
||||
--TEST--
|
||||
Bug #42802 (Namespace not supported in typehints)
|
||||
Bug #42802 (Namespace not supported in types)
|
||||
--FILE--
|
||||
<?php
|
||||
namespace foo;
|
||||
|
@ -5,4 +5,4 @@ Bug #69767 (Default parameter value with wrong type segfaults)
|
||||
function foo(String $bar = 0) {}
|
||||
?>
|
||||
--EXPECTF--
|
||||
Fatal error: Default value for parameters with a string type hint can only be string or NULL in %sbug69767.php on line %d
|
||||
Fatal error: Default value for parameters with a string type can only be string or NULL in %sbug69767.php on line %d
|
||||
|
@ -1,5 +1,5 @@
|
||||
--TEST--
|
||||
Closure 059: Closure type hinting
|
||||
Closure 059: Closure type declaration
|
||||
--FILE--
|
||||
<?php
|
||||
class A {
|
||||
|
@ -1,5 +1,5 @@
|
||||
--TEST--
|
||||
errmsg: default value for parameters with array type hint can only be an array or NULL
|
||||
errmsg: default value for parameters with array type can only be an array or NULL
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
@ -11,4 +11,4 @@ class test {
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
Fatal error: Default value for parameters with array type hint can only be an array or NULL in %s on line %d
|
||||
Fatal error: Default value for parameters with array type can only be an array or NULL in %s on line %d
|
||||
|
@ -58,7 +58,7 @@ $gen->next();
|
||||
var_dump($gen->getReturn());
|
||||
|
||||
// Explicit value-less return also results in a NULL generator
|
||||
// return value and there is no interference with type hints
|
||||
// return value and there is no interference with type declarations
|
||||
function gen6() : Generator {
|
||||
return;
|
||||
yield 24;
|
||||
|
@ -1,5 +1,5 @@
|
||||
--TEST--
|
||||
055: typehints in namespaces
|
||||
055: types in namespaces
|
||||
--FILE--
|
||||
<?php
|
||||
namespace test\ns1;
|
||||
|
@ -1,5 +1,5 @@
|
||||
--TEST--
|
||||
Return type hinting for internal functions
|
||||
Return type for internal functions
|
||||
|
||||
--SKIPIF--
|
||||
<?php
|
||||
|
@ -1,5 +1,5 @@
|
||||
--TEST--
|
||||
Return type hinting for internal functions 2
|
||||
Return type for internal functions 2
|
||||
|
||||
--SKIPIF--
|
||||
<?php
|
||||
|
@ -1,5 +1,5 @@
|
||||
--TEST--
|
||||
Return type hinting and Reflection::export()
|
||||
Return type and Reflection::export()
|
||||
|
||||
--SKIPIF--
|
||||
<?php
|
||||
|
@ -1,5 +1,5 @@
|
||||
--TEST--
|
||||
Array type hint
|
||||
Array type declaration
|
||||
--FILE--
|
||||
<?php
|
||||
function foo(array $a) {
|
||||
@ -12,8 +12,8 @@ foo(123);
|
||||
--EXPECTF--
|
||||
3
|
||||
|
||||
Fatal error: Uncaught TypeError: Argument 1 passed to foo() must be of the type array, integer given, called in %sarray_type_hint_001.php on line 7 and defined in %sarray_type_hint_001.php:2
|
||||
Fatal error: Uncaught TypeError: Argument 1 passed to foo() must be of the type array, integer given, called in %s on line 7 and defined in %s:2
|
||||
Stack trace:
|
||||
#0 %s(%d): foo(123)
|
||||
#1 {main}
|
||||
thrown in %sarray_type_hint_001.php on line 2
|
||||
thrown in %s on line 2
|
@ -1,5 +1,5 @@
|
||||
--TEST--
|
||||
callable type hint#001
|
||||
callable type#001
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
@ -21,7 +21,7 @@ foo($closure);
|
||||
string(6) "strpos"
|
||||
string(3) "foo"
|
||||
|
||||
Deprecated: Non-static method bar::baz() should not be called statically in %scallable_type_hint_001.php on line %d
|
||||
Deprecated: Non-static method bar::baz() should not be called statically in %s on line %d
|
||||
array(2) {
|
||||
[0]=>
|
||||
string(3) "bar"
|
@ -1,5 +1,5 @@
|
||||
--TEST--
|
||||
callable type hint#002 - Reflection
|
||||
callable type#002 - Reflection
|
||||
--FILE--
|
||||
<?php
|
||||
|
@ -1,5 +1,5 @@
|
||||
--TEST--
|
||||
callable type hint#003
|
||||
callable type#003
|
||||
--FILE--
|
||||
<?php
|
||||
|
@ -1,5 +1,5 @@
|
||||
--TEST--
|
||||
Closure with variadic type hint
|
||||
Closure with variadic type declaration
|
||||
--FILE--
|
||||
<?php
|
||||
$f = function (stdClass ...$a) {
|
@ -1,5 +1,5 @@
|
||||
--TEST--
|
||||
Inexistent class as typehint receiving scalar argument
|
||||
Inexistent class as type receiving scalar argument
|
||||
--FILE--
|
||||
<?php
|
||||
|
@ -1,5 +1,5 @@
|
||||
--TEST--
|
||||
Scalar type hint - internal function strict mode
|
||||
Scalar type - internal function strict mode
|
||||
--FILE--
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
@ -32,4 +32,4 @@ try {
|
||||
*** Trying Array Map With Invalid Callback
|
||||
*** Caught array_map() expects parameter 1 to be a valid callback, first array member is not a valid class name or object
|
||||
*** Trying Strlen With Float
|
||||
*** Caught strlen() expects parameter 1 to be string, float given
|
||||
*** Caught strlen() expects parameter 1 to be string, float given
|
@ -1,5 +1,5 @@
|
||||
--TEST--
|
||||
Scalar type hint basics
|
||||
Scalar type basics
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
@ -45,7 +45,7 @@ $values = [
|
||||
];
|
||||
|
||||
foreach ($functions as $type => $function) {
|
||||
echo PHP_EOL, "Testing '$type' typehint:", PHP_EOL;
|
||||
echo PHP_EOL, "Testing '$type' type:", PHP_EOL;
|
||||
foreach ($values as $value) {
|
||||
echo PHP_EOL . "*** Trying ";
|
||||
var_dump($value);
|
||||
@ -60,7 +60,7 @@ echo PHP_EOL . "Done";
|
||||
?>
|
||||
--EXPECTF--
|
||||
|
||||
Testing 'int' typehint:
|
||||
Testing 'int' type:
|
||||
|
||||
*** Trying int(1)
|
||||
int(1)
|
||||
@ -114,7 +114,7 @@ int(0)
|
||||
*** Trying resource(%d) of type (stream)
|
||||
*** Caught Argument 1 passed to {closure}() must be of the type integer, resource given, called in %s on line %d
|
||||
|
||||
Testing 'float' typehint:
|
||||
Testing 'float' type:
|
||||
|
||||
*** Trying int(1)
|
||||
float(1)
|
||||
@ -168,7 +168,7 @@ float(0)
|
||||
*** Trying resource(%d) of type (stream)
|
||||
*** Caught Argument 1 passed to {closure}() must be of the type float, resource given, called in %s on line %d
|
||||
|
||||
Testing 'string' typehint:
|
||||
Testing 'string' type:
|
||||
|
||||
*** Trying int(1)
|
||||
string(1) "1"
|
||||
@ -221,7 +221,7 @@ string(6) "foobar"
|
||||
*** Trying resource(%d) of type (stream)
|
||||
*** Caught Argument 1 passed to {closure}() must be of the type string, resource given, called in %s on line %d
|
||||
|
||||
Testing 'bool' typehint:
|
||||
Testing 'bool' type:
|
||||
|
||||
*** Trying int(1)
|
||||
bool(true)
|
@ -1,5 +1,5 @@
|
||||
--TEST--
|
||||
Scalar type hint - default via constants
|
||||
Scalar type - default via constants
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
@ -80,4 +80,4 @@ string(14) "this is a test"
|
||||
Testing int with default null constant
|
||||
NULL
|
||||
Testing int with null null constant
|
||||
NULL
|
||||
NULL
|
@ -1,5 +1,5 @@
|
||||
--TEST--
|
||||
Scalar type hint - default via constants - error condition
|
||||
Scalar type - default via constants - error condition
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
@ -17,4 +17,4 @@ Fatal error: Uncaught TypeError: Argument 1 passed to int_val() must be of the t
|
||||
Stack trace:
|
||||
#0 %s(%d): int_val()
|
||||
#1 {main}
|
||||
thrown in %s on line %d
|
||||
thrown in %s on line %d
|
@ -1,5 +1,5 @@
|
||||
--TEST--
|
||||
Float type hint should allow an integer as default even with strict types
|
||||
Float type should allow an integer as default even with strict types
|
||||
--FILE--
|
||||
<?php
|
||||
|
@ -1,5 +1,5 @@
|
||||
--TEST--
|
||||
Float type hint should allow an integer as default
|
||||
Float type should allow an integer as default
|
||||
--FILE--
|
||||
<?php
|
||||
|
@ -0,0 +1,16 @@
|
||||
--TEST--
|
||||
Float type should not allow invalid types as default
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
function test(float $arg = true)
|
||||
{
|
||||
var_dump($arg);
|
||||
}
|
||||
|
||||
test();
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
|
||||
Fatal error: Default value for parameters with a float type can only be float, integer, or NULL in %s on line %d
|
@ -1,5 +1,5 @@
|
||||
--TEST--
|
||||
Scalar type hint missing parameters
|
||||
Scalar type missing parameters
|
||||
--FILE--
|
||||
<?php
|
||||
|
@ -1,5 +1,5 @@
|
||||
--TEST--
|
||||
Scalar type hint nullability
|
||||
Scalar type nullability
|
||||
--FILE--
|
||||
<?php
|
||||
|
@ -1,5 +1,5 @@
|
||||
--TEST--
|
||||
Scalar type hint - disallow relative typehints
|
||||
Scalar type - disallow relative types
|
||||
--FILE--
|
||||
<?php
|
||||
|
@ -1,5 +1,5 @@
|
||||
--TEST--
|
||||
Scalar type hint names cannot be used as class, trait or interface names (2)
|
||||
Scalar type names cannot be used as class, trait or interface names (2)
|
||||
--FILE--
|
||||
<?php
|
||||
|
@ -1,5 +1,5 @@
|
||||
--TEST--
|
||||
Scalar type hint names cannot be used as class, trait or interface names (2) - class_alias
|
||||
Scalar type names cannot be used as class, trait or interface names (2) - class_alias
|
||||
--FILE--
|
||||
<?php
|
||||
|
@ -1,5 +1,5 @@
|
||||
--TEST--
|
||||
Scalar type hint names cannot be used as class, trait or interface names (2) - use
|
||||
Scalar type names cannot be used as class, trait or interface names (2) - use
|
||||
--FILE--
|
||||
<?php
|
||||
|
@ -1,5 +1,5 @@
|
||||
--TEST--
|
||||
Scalar type hint names cannot be used as class, trait or interface names (3)
|
||||
Scalar type names cannot be used as class, trait or interface names (3)
|
||||
--FILE--
|
||||
<?php
|
||||
|
@ -1,5 +1,5 @@
|
||||
--TEST--
|
||||
Scalar type hint names cannot be used as class, trait or interface names (3) - class_alias
|
||||
Scalar type names cannot be used as class, trait or interface names (3) - class_alias
|
||||
--FILE--
|
||||
<?php
|
||||
|
@ -1,5 +1,5 @@
|
||||
--TEST--
|
||||
Scalar type hint names cannot be used as class, trait or interface names (3) - use
|
||||
Scalar type names cannot be used as class, trait or interface names (3) - use
|
||||
--FILE--
|
||||
<?php
|
||||
|
@ -1,5 +1,5 @@
|
||||
--TEST--
|
||||
Scalar type hint names cannot be used as class, trait or interface names (4)
|
||||
Scalar type names cannot be used as class, trait or interface names (4)
|
||||
--FILE--
|
||||
<?php
|
||||
|
@ -1,5 +1,5 @@
|
||||
--TEST--
|
||||
Scalar type hint names cannot be used as class, trait or interface names (4) - class_alias
|
||||
Scalar type names cannot be used as class, trait or interface names (4) - class_alias
|
||||
--FILE--
|
||||
<?php
|
||||
|
@ -1,5 +1,5 @@
|
||||
--TEST--
|
||||
Scalar type hint names cannot be used as class, trait or interface names (4) - use
|
||||
Scalar type names cannot be used as class, trait or interface names (4) - use
|
||||
--FILE--
|
||||
<?php
|
||||
|
@ -1,5 +1,5 @@
|
||||
--TEST--
|
||||
Scalar type hint names cannot be used as class, trait or interface names (6)
|
||||
Scalar type names cannot be used as class, trait or interface names (6)
|
||||
--FILE--
|
||||
<?php
|
||||
|
@ -1,5 +1,5 @@
|
||||
--TEST--
|
||||
Scalar type hint names cannot be used as class, trait or interface names (6) - class_alias
|
||||
Scalar type names cannot be used as class, trait or interface names (6) - class_alias
|
||||
--FILE--
|
||||
<?php
|
||||
|
@ -1,5 +1,5 @@
|
||||
--TEST--
|
||||
Scalar type hint names cannot be used as class, trait or interface names (6) - use
|
||||
Scalar type names cannot be used as class, trait or interface names (6) - use
|
||||
--FILE--
|
||||
<?php
|
||||
|
@ -1,5 +1,5 @@
|
||||
--TEST--
|
||||
Scalar type hint names cannot be used as class, trait or interface names (7)
|
||||
Scalar type names cannot be used as class, trait or interface names (7)
|
||||
--FILE--
|
||||
<?php
|
||||
namespace foo;
|
@ -1,5 +1,5 @@
|
||||
--TEST--
|
||||
Return scalar type hint basics
|
||||
Return scalar type basics
|
||||
--SKIPIF--
|
||||
<?php if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only"); ?>
|
||||
--FILE--
|
||||
@ -48,7 +48,7 @@ $values = [
|
||||
];
|
||||
|
||||
foreach ($functions as $type => $function) {
|
||||
echo PHP_EOL, "Testing '$type' typehint:", PHP_EOL;
|
||||
echo PHP_EOL, "Testing '$type' type:", PHP_EOL;
|
||||
foreach ($values as $value) {
|
||||
echo "*** Trying ";
|
||||
var_dump($value);
|
||||
@ -63,7 +63,7 @@ foreach ($functions as $type => $function) {
|
||||
echo PHP_EOL . "Done";
|
||||
?>
|
||||
--EXPECTF--
|
||||
Testing 'int' typehint:
|
||||
Testing 'int' type:
|
||||
*** Trying int(1)
|
||||
int(1)
|
||||
*** Trying string(1) "1"
|
||||
@ -101,7 +101,7 @@ int(0)
|
||||
*** Trying resource(5) of type (stream)
|
||||
*** Caught Return value of {closure}() must be of the type integer, resource returned in %s on line %d
|
||||
|
||||
Testing 'float' typehint:
|
||||
Testing 'float' type:
|
||||
*** Trying int(1)
|
||||
float(1)
|
||||
*** Trying string(1) "1"
|
||||
@ -139,7 +139,7 @@ float(0)
|
||||
*** Trying resource(5) of type (stream)
|
||||
*** Caught Return value of {closure}() must be of the type float, resource returned in %s on line %d
|
||||
|
||||
Testing 'string' typehint:
|
||||
Testing 'string' type:
|
||||
*** Trying int(1)
|
||||
string(1) "1"
|
||||
*** Trying string(1) "1"
|
||||
@ -176,7 +176,7 @@ string(6) "foobar"
|
||||
*** Trying resource(5) of type (stream)
|
||||
*** Caught Return value of {closure}() must be of the type string, resource returned in %s on line %d
|
||||
|
||||
Testing 'bool' typehint:
|
||||
Testing 'bool' type:
|
||||
*** Trying int(1)
|
||||
bool(true)
|
||||
*** Trying string(1) "1"
|
@ -1,5 +1,5 @@
|
||||
--TEST--
|
||||
Return scalar type hint basics
|
||||
Return scalar type basics
|
||||
--SKIPIF--
|
||||
<?php if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only"); ?>
|
||||
--FILE--
|
||||
@ -48,7 +48,7 @@ $values = [
|
||||
];
|
||||
|
||||
foreach ($functions as $type => $function) {
|
||||
echo PHP_EOL, "Testing '$type' typehint:", PHP_EOL;
|
||||
echo PHP_EOL, "Testing '$type' type:", PHP_EOL;
|
||||
foreach ($values as $value) {
|
||||
echo "*** Trying ";
|
||||
var_dump($value);
|
||||
@ -63,7 +63,7 @@ foreach ($functions as $type => $function) {
|
||||
echo PHP_EOL . "Done";
|
||||
?>
|
||||
--EXPECTF--
|
||||
Testing 'int' typehint:
|
||||
Testing 'int' type:
|
||||
*** Trying int(1)
|
||||
int(1)
|
||||
*** Trying string(1) "1"
|
||||
@ -101,7 +101,7 @@ int(0)
|
||||
*** Trying resource(5) of type (stream)
|
||||
*** Caught Return value of {closure}() must be of the type integer, resource returned in %s on line %d
|
||||
|
||||
Testing 'float' typehint:
|
||||
Testing 'float' type:
|
||||
*** Trying int(1)
|
||||
float(1)
|
||||
*** Trying string(1) "1"
|
||||
@ -139,7 +139,7 @@ float(0)
|
||||
*** Trying resource(5) of type (stream)
|
||||
*** Caught Return value of {closure}() must be of the type float, resource returned in %s on line %d
|
||||
|
||||
Testing 'string' typehint:
|
||||
Testing 'string' type:
|
||||
*** Trying int(1)
|
||||
string(1) "1"
|
||||
*** Trying string(1) "1"
|
||||
@ -176,7 +176,7 @@ string(6) "foobar"
|
||||
*** Trying resource(5) of type (stream)
|
||||
*** Caught Return value of {closure}() must be of the type string, resource returned in %s on line %d
|
||||
|
||||
Testing 'bool' typehint:
|
||||
Testing 'bool' type:
|
||||
*** Trying int(1)
|
||||
bool(true)
|
||||
*** Trying string(1) "1"
|
@ -1,5 +1,5 @@
|
||||
--TEST--
|
||||
Scalar type hint strict mode
|
||||
Scalar type strict mode
|
||||
--SKIPIF--
|
||||
<?php if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only"); ?>
|
||||
--FILE--
|
||||
@ -49,7 +49,7 @@ $values = [
|
||||
];
|
||||
|
||||
foreach ($functions as $type => $function) {
|
||||
echo PHP_EOL, "Testing '$type' typehint:", PHP_EOL;
|
||||
echo PHP_EOL, "Testing '$type' type:", PHP_EOL;
|
||||
foreach ($values as $value) {
|
||||
echo PHP_EOL . "*** Trying ";
|
||||
var_dump($value);
|
||||
@ -64,7 +64,7 @@ foreach ($functions as $type => $function) {
|
||||
echo PHP_EOL . "Done";
|
||||
?>
|
||||
--EXPECTF--
|
||||
Testing 'int' typehint:
|
||||
Testing 'int' type:
|
||||
|
||||
*** Trying int(1)
|
||||
int(1)
|
||||
@ -117,7 +117,7 @@ int(2147483647)
|
||||
*** Trying resource(5) of type (stream)
|
||||
*** Caught Argument 1 passed to {closure}() must be of the type integer, resource given, called in %s on line %d
|
||||
|
||||
Testing 'float' typehint:
|
||||
Testing 'float' type:
|
||||
|
||||
*** Trying int(1)
|
||||
float(1)
|
||||
@ -170,7 +170,7 @@ float(NAN)
|
||||
*** Trying resource(5) of type (stream)
|
||||
*** Caught Argument 1 passed to {closure}() must be of the type float, resource given, called in %s on line %d
|
||||
|
||||
Testing 'string' typehint:
|
||||
Testing 'string' type:
|
||||
|
||||
*** Trying int(1)
|
||||
*** Caught Argument 1 passed to {closure}() must be of the type string, integer given, called in %s on line %d
|
||||
@ -223,7 +223,7 @@ string(0) ""
|
||||
*** Trying resource(5) of type (stream)
|
||||
*** Caught Argument 1 passed to {closure}() must be of the type string, resource given, called in %s on line %d
|
||||
|
||||
Testing 'bool' typehint:
|
||||
Testing 'bool' type:
|
||||
|
||||
*** Trying int(1)
|
||||
*** Caught Argument 1 passed to {closure}() must be of the type boolean, integer given, called in %s on line %d
|
@ -1,5 +1,5 @@
|
||||
--TEST--
|
||||
Scalar type hint strict mode
|
||||
Scalar type strict mode
|
||||
--SKIPIF--
|
||||
<?php if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only"); ?>
|
||||
--FILE--
|
||||
@ -49,7 +49,7 @@ $values = [
|
||||
];
|
||||
|
||||
foreach ($functions as $type => $function) {
|
||||
echo PHP_EOL, "Testing '$type' typehint:", PHP_EOL;
|
||||
echo PHP_EOL, "Testing '$type' type:", PHP_EOL;
|
||||
foreach ($values as $value) {
|
||||
echo PHP_EOL . "*** Trying ";
|
||||
var_dump($value);
|
||||
@ -64,7 +64,7 @@ foreach ($functions as $type => $function) {
|
||||
echo PHP_EOL . "Done";
|
||||
?>
|
||||
--EXPECTF--
|
||||
Testing 'int' typehint:
|
||||
Testing 'int' type:
|
||||
|
||||
*** Trying int(1)
|
||||
int(1)
|
||||
@ -117,7 +117,7 @@ int(9223372036854775807)
|
||||
*** Trying resource(5) of type (stream)
|
||||
*** Caught Argument 1 passed to {closure}() must be of the type integer, resource given, called in %s on line %d
|
||||
|
||||
Testing 'float' typehint:
|
||||
Testing 'float' type:
|
||||
|
||||
*** Trying int(1)
|
||||
float(1)
|
||||
@ -170,7 +170,7 @@ float(NAN)
|
||||
*** Trying resource(5) of type (stream)
|
||||
*** Caught Argument 1 passed to {closure}() must be of the type float, resource given, called in %s on line %d
|
||||
|
||||
Testing 'string' typehint:
|
||||
Testing 'string' type:
|
||||
|
||||
*** Trying int(1)
|
||||
*** Caught Argument 1 passed to {closure}() must be of the type string, integer given, called in %s on line %d
|
||||
@ -223,7 +223,7 @@ string(0) ""
|
||||
*** Trying resource(5) of type (stream)
|
||||
*** Caught Argument 1 passed to {closure}() must be of the type string, resource given, called in %s on line %d
|
||||
|
||||
Testing 'bool' typehint:
|
||||
Testing 'bool' type:
|
||||
|
||||
*** Trying int(1)
|
||||
*** Caught Argument 1 passed to {closure}() must be of the type boolean, integer given, called in %s on line %d
|
@ -1,5 +1,5 @@
|
||||
--TEST--
|
||||
Strict scalar type hint basics
|
||||
Strict scalar type basics
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
@ -48,7 +48,7 @@ function type($value) {
|
||||
}
|
||||
|
||||
foreach ($functions as $type => $function) {
|
||||
echo PHP_EOL, "Testing '$type' typehint:", PHP_EOL;
|
||||
echo PHP_EOL, "Testing '$type' type:", PHP_EOL;
|
||||
foreach ($values as $value) {
|
||||
$errored = false;
|
||||
echo PHP_EOL . "*** Trying ", type($value), " value", PHP_EOL;
|
||||
@ -62,7 +62,7 @@ foreach ($functions as $type => $function) {
|
||||
echo PHP_EOL . "Done";
|
||||
?>
|
||||
--EXPECTF--
|
||||
Testing 'int' typehint:
|
||||
Testing 'int' type:
|
||||
|
||||
*** Trying integer value
|
||||
int(1)
|
||||
@ -91,7 +91,7 @@ int(1)
|
||||
*** Trying resource value
|
||||
*** Caught Argument 1 passed to {closure}() must be of the type integer, resource given, called in %s on line %d
|
||||
|
||||
Testing 'float' typehint:
|
||||
Testing 'float' type:
|
||||
|
||||
*** Trying integer value
|
||||
float(1)
|
||||
@ -120,7 +120,7 @@ float(1)
|
||||
*** Trying resource value
|
||||
*** Caught Argument 1 passed to {closure}() must be of the type float, resource given, called in %s on line %d
|
||||
|
||||
Testing 'string' typehint:
|
||||
Testing 'string' type:
|
||||
|
||||
*** Trying integer value
|
||||
*** Caught Argument 1 passed to {closure}() must be of the type string, integer given, called in %s on line %d
|
||||
@ -149,7 +149,7 @@ string(1) "1"
|
||||
*** Trying resource value
|
||||
*** Caught Argument 1 passed to {closure}() must be of the type string, resource given, called in %s on line %d
|
||||
|
||||
Testing 'bool' typehint:
|
||||
Testing 'bool' type:
|
||||
|
||||
*** Trying integer value
|
||||
*** Caught Argument 1 passed to {closure}() must be of the type boolean, integer given, called in %s on line %d
|
@ -1,5 +1,5 @@
|
||||
--TEST--
|
||||
Weak scalar type hints, with references
|
||||
Weak scalar types, with references
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
@ -12,7 +12,7 @@ function to_bool(bool &$x) {}
|
||||
|
||||
$x = 1.0;
|
||||
var_dump($x);
|
||||
to_int($x); // because $x is by-reference, the weak type hint converts it
|
||||
to_int($x); // because $x is by-reference, the weak type converts it
|
||||
var_dump($x);
|
||||
to_float($x);
|
||||
var_dump($x);
|
@ -1,16 +0,0 @@
|
||||
--TEST--
|
||||
Float type hint should not allow invalid types as default
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
function test(float $arg = true)
|
||||
{
|
||||
var_dump($arg);
|
||||
}
|
||||
|
||||
test();
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
|
||||
Fatal error: Default value for parameters with a float type hint can only be float, integer, or NULL in %s on line %d
|
@ -1,5 +1,5 @@
|
||||
--TEST--
|
||||
Variadic arguments enforce typehints
|
||||
Variadic arguments enforce types
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
--TEST--
|
||||
Error suppression for typehints on variadic arguments works
|
||||
Error suppression for types on variadic arguments works
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
|
@ -4712,7 +4712,7 @@ void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast) /* {{{ */
|
||||
zend_arg_info *arg_infos;
|
||||
|
||||
if (return_type_ast) {
|
||||
/* Use op_array->arg_info[-1] for return type hinting */
|
||||
/* Use op_array->arg_info[-1] for return type */
|
||||
arg_infos = safe_emalloc(sizeof(zend_arg_info), list->children + 1, 0);
|
||||
arg_infos->name = NULL;
|
||||
arg_infos->pass_by_reference = (op_array->fn_flags & ZEND_ACC_RETURN_REFERENCE) != 0;
|
||||
@ -4825,31 +4825,31 @@ void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast) /* {{{ */
|
||||
&& !Z_CONSTANT(default_node.u.constant)
|
||||
) {
|
||||
zend_error_noreturn(E_COMPILE_ERROR, "Default value for parameters "
|
||||
"with array type hint can only be an array or NULL");
|
||||
"with array type can only be an array or NULL");
|
||||
}
|
||||
} else if (arg_info->type_hint == IS_CALLABLE && default_ast) {
|
||||
if (!has_null_default && !Z_CONSTANT(default_node.u.constant)) {
|
||||
zend_error_noreturn(E_COMPILE_ERROR, "Default value for parameters "
|
||||
"with callable type hint can only be NULL");
|
||||
"with callable type can only be NULL");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (default_ast && !has_null_default && !Z_CONSTANT(default_node.u.constant)) {
|
||||
if (arg_info->class_name) {
|
||||
zend_error_noreturn(E_COMPILE_ERROR, "Default value for parameters "
|
||||
"with a class type hint can only be NULL");
|
||||
"with a class type can only be NULL");
|
||||
} else switch (arg_info->type_hint) {
|
||||
case IS_DOUBLE:
|
||||
if (Z_TYPE(default_node.u.constant) != IS_DOUBLE && Z_TYPE(default_node.u.constant) != IS_LONG) {
|
||||
zend_error_noreturn(E_COMPILE_ERROR, "Default value for parameters "
|
||||
"with a float type hint can only be float, integer, or NULL");
|
||||
"with a float type can only be float, integer, or NULL");
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
if (!ZEND_SAME_FAKE_TYPE(arg_info->type_hint, Z_TYPE(default_node.u.constant))) {
|
||||
zend_error_noreturn(E_COMPILE_ERROR, "Default value for parameters "
|
||||
"with a %s type hint can only be %s or NULL",
|
||||
"with a %s type can only be %s or NULL",
|
||||
zend_get_type_by_const(arg_info->type_hint), zend_get_type_by_const(arg_info->type_hint));
|
||||
}
|
||||
break;
|
||||
|
@ -275,7 +275,7 @@ typedef struct _zend_oparray_context {
|
||||
/* class has magic methods __get/__set/__unset/__isset that use guards */
|
||||
#define ZEND_ACC_USE_GUARDS 0x1000000
|
||||
|
||||
/* function has arguments with type hinting */
|
||||
/* function has typed arguments */
|
||||
#define ZEND_ACC_HAS_TYPE_HINTS 0x10000000
|
||||
|
||||
/* op_array has finally blocks */
|
||||
@ -284,7 +284,7 @@ typedef struct _zend_oparray_context {
|
||||
/* internal function is allocated at arena */
|
||||
#define ZEND_ACC_ARENA_ALLOCATED 0x20000000
|
||||
|
||||
/* Function has a return type hint (or class has such non-private function) */
|
||||
/* Function has a return type (or class has such non-private function) */
|
||||
#define ZEND_ACC_HAS_RETURN_TYPE 0x40000000
|
||||
|
||||
/* op_array uses strict mode types */
|
||||
@ -339,7 +339,7 @@ typedef struct _zend_arg_info {
|
||||
/* the following structure repeats the layout of zend_internal_arg_info,
|
||||
* but its fields have different meaning. It's used as the first element of
|
||||
* arg_info array to define properties of internal functions.
|
||||
* It's also used for return type hinting.
|
||||
* It's also used for the return type.
|
||||
*/
|
||||
typedef struct _zend_internal_function_info {
|
||||
zend_uintptr_t required_num_args;
|
||||
|
@ -170,7 +170,7 @@ char *zend_visibility_string(uint32_t fn_flags) /* {{{ */
|
||||
static int zend_do_perform_type_hint_check(const zend_function *fe, zend_arg_info *fe_arg_info, const zend_function *proto, zend_arg_info *proto_arg_info) /* {{{ */
|
||||
{
|
||||
if (ZEND_LOG_XOR(fe_arg_info->class_name, proto_arg_info->class_name)) {
|
||||
/* Only one has a type hint and the other one doesn't */
|
||||
/* Only one has a type declaration and the other one doesn't */
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -239,7 +239,7 @@ static int zend_do_perform_type_hint_check(const zend_function *fe, zend_arg_inf
|
||||
}
|
||||
|
||||
if (fe_arg_info->type_hint != proto_arg_info->type_hint) {
|
||||
/* Incompatible type hint */
|
||||
/* Incompatible type */
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
--TEST--
|
||||
ZE2 type hinting
|
||||
ZE2 type
|
||||
--SKIPIF--
|
||||
<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 needed'); ?>
|
||||
--FILE--
|
||||
@ -11,4 +11,4 @@ class T {
|
||||
?>
|
||||
--EXPECTF--
|
||||
|
||||
Fatal error: Default value for parameters with a class type hint can only be NULL in %stype_hints_003.php on line 3
|
||||
Fatal error: Default value for parameters with a class type can only be NULL in %stype_hints_003.php on line 3
|
||||
|
Loading…
Reference in New Issue
Block a user