31 changed files with 3513 additions and 2169 deletions
-
1NEWS
-
2Zend/tests/array_type_hint_001.phpt
-
38Zend/tests/hint/param_type_hint_001.phpt
-
97Zend/tests/hint/param_type_hint_002.phpt
-
16Zend/tests/hint/param_type_hint_003.phpt
-
16Zend/tests/hint/param_type_hint_004.phpt
-
23Zend/tests/hint/param_type_hint_005.phpt
-
22Zend/tests/hint/param_type_hint_006.phpt
-
46Zend/tests/hint/param_type_hint_007.phpt
-
20Zend/tests/hint/param_type_hint_008.phpt
-
17Zend/tests/hint/param_type_hint_009.phpt
-
28Zend/tests/hint/param_type_hint_010.phpt
-
15Zend/tests/hint/param_type_hint_011.phpt
-
18Zend/tests/hint/param_type_hint_012.phpt
-
16Zend/tests/hint/param_type_hint_013.phpt
-
16Zend/tests/hint/param_type_hint_014.phpt
-
19Zend/tests/hint/param_type_hint_015.phpt
-
22Zend/tests/hint/param_type_hint_016.phpt
-
14Zend/tests/hint/param_type_hint_017.phpt
-
2Zend/tests/ns_071.phpt
-
2Zend/zend.h
-
1Zend/zend_API.c
-
5Zend/zend_API.h
-
38Zend/zend_compile.c
-
2Zend/zend_compile.h
-
16Zend/zend_execute.c
-
16Zend/zend_language_parser.y
-
4996Zend/zend_language_scanner.c
-
46Zend/zend_language_scanner.l
-
2Zend/zend_language_scanner_defs.h
-
110ext/reflection/php_reflection.c
@ -0,0 +1,38 @@ |
|||
--TEST-- |
|||
Parameter type hint - Testing integer hint |
|||
--FILE-- |
|||
<?php |
|||
|
|||
function test_int($x, int $a = 1) { |
|||
} |
|||
|
|||
test_int(1); |
|||
print "Ok\n"; |
|||
|
|||
test_int('1211'); |
|||
print "Ok\n"; |
|||
|
|||
test_int(null); |
|||
print "Ok\n"; |
|||
|
|||
test_int(1, 1); |
|||
print "Ok\n"; |
|||
|
|||
test_int(null, '1211'); |
|||
print "Ok\n"; |
|||
|
|||
?> |
|||
--EXPECTF-- |
|||
Ok |
|||
Ok |
|||
Ok |
|||
Ok |
|||
|
|||
Catchable fatal error: Argument 2 passed to test_int() must be of the type integer, string given, called in %s on line %d and defined in %s on line %d |
|||
--UEXPECTF-- |
|||
Ok |
|||
Ok |
|||
Ok |
|||
Ok |
|||
|
|||
Catchable fatal error: Argument 2 passed to test_int() must be of the type integer, Unicode string given, called in %s on line %d and defined in %s on line %d |
|||
@ -0,0 +1,97 @@ |
|||
--TEST-- |
|||
Parameter type hint - Reflection |
|||
--FILE-- |
|||
<?php |
|||
|
|||
function test(int $a, double $b, string $c, boolean $d = true, resource $e, array $f = array(), object $g) { |
|||
} |
|||
|
|||
$func = new ReflectionFunction('test'); |
|||
Reflection::Export($func); |
|||
|
|||
foreach ($func->getParameters() as $i => $param) { |
|||
printf( |
|||
"-- Parameter #%d: %s {\n". |
|||
" Allows NULL: %s\n". |
|||
" Hint Type: %s\n". |
|||
" Passed to by reference: %s\n". |
|||
" Is optional?: %s\n", |
|||
$i, |
|||
$param->getName(), |
|||
var_export($param->getClass(), 1), |
|||
$param->getTypeHint(), |
|||
var_export($param->allowsNull(), 1), |
|||
var_export($param->isPassedByReference(), 1), |
|||
$param->isOptional() ? 'yes' : 'no' |
|||
); |
|||
printf(" Int: %d | Double: %d | Bool: %d | String: %d | Resource: %d | Array: %d | Object: %d\n", |
|||
$param->isInt(), $param->isDouble(), $param->isBool(), $param->isString(), |
|||
$param->isResource(), $param->isArray(), $param->isObject()); |
|||
print "}\n"; |
|||
} |
|||
|
|||
?> |
|||
--EXPECTF-- |
|||
Function [ <user> function test ] { |
|||
@@ %s 3 - 4 |
|||
|
|||
- Parameters [7] { |
|||
Parameter #0 [ <required> integer $a ] |
|||
Parameter #1 [ <required> double $b ] |
|||
Parameter #2 [ <required> string $c ] |
|||
Parameter #3 [ <required> boolean $d ] |
|||
Parameter #4 [ <required> resource $e ] |
|||
Parameter #5 [ <required> array $f ] |
|||
Parameter #6 [ <required> object $g ] |
|||
} |
|||
} |
|||
|
|||
-- Parameter #0: a { |
|||
Allows NULL: NULL |
|||
Hint Type: integer |
|||
Passed to by reference: false |
|||
Is optional?: false |
|||
Int: 1 | Double: 0 | Bool: 0 | String: 0 | Resource: 0 | Array: 0 | Object: 0 |
|||
} |
|||
-- Parameter #1: b { |
|||
Allows NULL: NULL |
|||
Hint Type: double |
|||
Passed to by reference: false |
|||
Is optional?: false |
|||
Int: 0 | Double: 1 | Bool: 0 | String: 0 | Resource: 0 | Array: 0 | Object: 0 |
|||
} |
|||
-- Parameter #2: c { |
|||
Allows NULL: NULL |
|||
Hint Type: string |
|||
Passed to by reference: false |
|||
Is optional?: false |
|||
Int: 0 | Double: 0 | Bool: 0 | String: 1 | Resource: 0 | Array: 0 | Object: 0 |
|||
} |
|||
-- Parameter #3: d { |
|||
Allows NULL: NULL |
|||
Hint Type: boolean |
|||
Passed to by reference: false |
|||
Is optional?: false |
|||
Int: 0 | Double: 0 | Bool: 1 | String: 0 | Resource: 0 | Array: 0 | Object: 0 |
|||
} |
|||
-- Parameter #4: e { |
|||
Allows NULL: NULL |
|||
Hint Type: resource |
|||
Passed to by reference: false |
|||
Is optional?: false |
|||
Int: 0 | Double: 0 | Bool: 0 | String: 0 | Resource: 1 | Array: 0 | Object: 0 |
|||
} |
|||
-- Parameter #5: f { |
|||
Allows NULL: NULL |
|||
Hint Type: array |
|||
Passed to by reference: false |
|||
Is optional?: false |
|||
Int: 0 | Double: 0 | Bool: 0 | String: 0 | Resource: 0 | Array: 1 | Object: 0 |
|||
} |
|||
-- Parameter #6: g { |
|||
Allows NULL: NULL |
|||
Hint Type: object |
|||
Passed to by reference: false |
|||
Is optional?: false |
|||
Int: 0 | Double: 0 | Bool: 0 | String: 0 | Resource: 0 | Array: 0 | Object: 1 |
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
--TEST-- |
|||
Parameter type hint - Wrong parameter for integer |
|||
--FILE-- |
|||
<?php |
|||
|
|||
function test_int(int $a) { |
|||
echo $a, "\n"; |
|||
} |
|||
|
|||
test_int('+1'); |
|||
|
|||
?> |
|||
--EXPECTF-- |
|||
Catchable fatal error: Argument 1 passed to test_int() must be of the type integer, string given, called in %s on line %d and defined in %s on line %d |
|||
--UEXPECTF-- |
|||
Catchable fatal error: Argument 1 passed to test_int() must be of the type integer, Unicode string given, called in %s on line %d and defined in %s on line %d |
|||
@ -0,0 +1,16 @@ |
|||
--TEST-- |
|||
Parameter type hint - Wrong parameter for double |
|||
--FILE-- |
|||
<?php |
|||
|
|||
function test_double(real $a) { |
|||
echo $a, "\n"; |
|||
} |
|||
|
|||
test_double('+1.1'); |
|||
|
|||
?> |
|||
--EXPECTF-- |
|||
Catchable fatal error: Argument 1 passed to test_double() must be of the type double, string given, called in %s on line %d and defined in %s on line %d |
|||
--UEXPECTF-- |
|||
Catchable fatal error: Argument 1 passed to test_double() must be of the type double, Unicode string given, called in %s on line %d and defined in %s on line %d |
|||
@ -0,0 +1,23 @@ |
|||
--TEST-- |
|||
Parameter type hint - Wrong parameter for string |
|||
--FILE-- |
|||
<?php |
|||
|
|||
function test_str(string $a) { |
|||
echo $a, "\n"; |
|||
} |
|||
|
|||
test_str('+1.1'); |
|||
test_str('-.1'); |
|||
test_str('11213111112321312'); |
|||
test_str(''); |
|||
test_str(null); |
|||
|
|||
?> |
|||
--EXPECTF-- |
|||
+1.1 |
|||
-.1 |
|||
11213111112321312 |
|||
|
|||
|
|||
Catchable fatal error: Argument 1 passed to test_str() must be of the type string, null given, called in %s on line %d and defined in %s on line %d |
|||
@ -0,0 +1,22 @@ |
|||
--TEST-- |
|||
Parameter type hint - Testing NULL when allowed |
|||
--FILE-- |
|||
<?php |
|||
|
|||
function test_int(int $a = null) { |
|||
} |
|||
test_int(null); |
|||
|
|||
function test_double(double $a = null) { |
|||
} |
|||
test_double(null); |
|||
|
|||
function test_bool(bool $a = null) { |
|||
} |
|||
test_bool(null); |
|||
|
|||
print "Done"; |
|||
|
|||
?> |
|||
--EXPECT-- |
|||
Done |
|||
@ -0,0 +1,46 @@ |
|||
--TEST-- |
|||
Parameter type hint - Testing parameter with reference |
|||
--FILE-- |
|||
<?php |
|||
|
|||
/* string */ |
|||
function test_string(string &$a) { |
|||
$a .= '!!!'; |
|||
} |
|||
|
|||
$str = 'foo'; |
|||
test_string($str); |
|||
var_dump($str); |
|||
|
|||
/* integer */ |
|||
function test_int(int &$b) { |
|||
$b += 2; |
|||
} |
|||
|
|||
$b = 2; |
|||
test_int($b); |
|||
var_dump($b); |
|||
|
|||
/* object */ |
|||
function test_obj(object &$c) { |
|||
$c->tested = 1; |
|||
} |
|||
$c = new stdclass; |
|||
test_obj($c); |
|||
var_dump($c); |
|||
|
|||
?> |
|||
--EXPECT-- |
|||
string(6) "foo!!!" |
|||
int(4) |
|||
object(stdClass)#1 (1) { |
|||
["tested"]=> |
|||
int(1) |
|||
} |
|||
--UEXPECT-- |
|||
unicode(6) "foo!!!" |
|||
int(4) |
|||
object(stdClass)#1 (1) { |
|||
[u"tested"]=> |
|||
int(1) |
|||
} |
|||
@ -0,0 +1,20 @@ |
|||
--TEST-- |
|||
Parameter type hint - Testing string type hint with reference |
|||
--FILE-- |
|||
<?php |
|||
|
|||
function test(string &$a) { |
|||
$a .= '!!!'; |
|||
} |
|||
|
|||
$x = 'foo'; |
|||
|
|||
test($x); |
|||
|
|||
var_dump($x); |
|||
|
|||
?> |
|||
--EXPECT-- |
|||
string(6) "foo!!!" |
|||
--UEXPECT-- |
|||
unicode(6) "foo!!!" |
|||
@ -0,0 +1,17 @@ |
|||
--TEST-- |
|||
Parameter type hint - Testing default parameter value |
|||
--FILE-- |
|||
<?php |
|||
|
|||
function test(string &$a, integer $x = 1) { |
|||
var_dump($x); |
|||
} |
|||
|
|||
$y = 'foo'; |
|||
test($y, 2); |
|||
test($y); |
|||
|
|||
?> |
|||
--EXPECT-- |
|||
int(2) |
|||
int(1) |
|||
@ -0,0 +1,28 @@ |
|||
--TEST-- |
|||
Parameter type hint - Testing with heredoc |
|||
--FILE-- |
|||
<?php |
|||
|
|||
function test(string $str) { |
|||
} |
|||
|
|||
test(<<<FOO |
|||
test! |
|||
FOO |
|||
); |
|||
|
|||
test(<<<'FOO' |
|||
test! |
|||
FOO |
|||
); |
|||
|
|||
test(<<<"FOO" |
|||
test! |
|||
FOO |
|||
); |
|||
|
|||
print "Ok!"; |
|||
|
|||
?> |
|||
--EXPECT-- |
|||
Ok! |
|||
@ -0,0 +1,15 @@ |
|||
--TEST-- |
|||
Parameter type hint - Testing with undefined variable |
|||
--FILE-- |
|||
<?php |
|||
|
|||
function test(string $a) { |
|||
} |
|||
|
|||
test($x); |
|||
|
|||
?> |
|||
--EXPECTF-- |
|||
Notice: Undefined variable: x in %s on line %d |
|||
|
|||
Catchable fatal error: Argument 1 passed to test() must be of the type string, null given, called in %s on line %d and defined in %s on line %d |
|||
@ -0,0 +1,18 @@ |
|||
--TEST-- |
|||
Parameter type hint - Testing with lambda function |
|||
--FILE-- |
|||
<?php |
|||
|
|||
$test = create_function('integer $i', 'return $i + 1;'); |
|||
var_dump($test(1)); |
|||
var_dump($test('foo')); |
|||
|
|||
?> |
|||
--EXPECTF-- |
|||
int(2) |
|||
|
|||
Catchable fatal error: Argument 1 passed to __lambda_func() must be of the type integer, string given, called in %s on line %d and defined in %s(%d) : runtime-created function on line %d |
|||
--UEXPECTF-- |
|||
int(2) |
|||
|
|||
Catchable fatal error: Argument 1 passed to __lambda_func() must be of the type integer, Unicode string given, called in %s on line %d and defined in %s(%d) : runtime-created function on line %d |
|||
@ -0,0 +1,16 @@ |
|||
--TEST-- |
|||
Parameter type hint - Testing with lambda function using 2 parameters |
|||
--FILE-- |
|||
<?php |
|||
|
|||
$test = create_function('integer $i, string $j', 'return $i + $j;'); |
|||
var_dump($test(1, 'foo')); |
|||
var_dump($test(1, '1')); |
|||
var_dump($test(1, NULL)); |
|||
|
|||
?> |
|||
--EXPECTF-- |
|||
int(1) |
|||
int(2) |
|||
|
|||
Catchable fatal error: Argument 2 passed to __lambda_func() must be of the type string, null given, called in %s on line %d and defined in %s(%d) : runtime-created function on line %d |
|||
@ -0,0 +1,16 @@ |
|||
--TEST-- |
|||
Parameter type hint - Testing in function inside function |
|||
--FILE-- |
|||
<?php |
|||
|
|||
function a() { |
|||
function b(real $c) { |
|||
} |
|||
return b(1); |
|||
} |
|||
|
|||
a(); |
|||
|
|||
?> |
|||
--EXPECTF-- |
|||
Catchable fatal error: Argument 1 passed to b() must be of the type double, integer given, called in %s on line %d and defined in %s on line %d |
|||
@ -0,0 +1,19 @@ |
|||
--TEST-- |
|||
Parameter type hint - Testing with call_user_func() |
|||
--FILE-- |
|||
<?php |
|||
|
|||
function test(bool $b) { |
|||
print "ok\n"; |
|||
} |
|||
|
|||
call_user_func('test', true); |
|||
call_user_func('test', false); |
|||
call_user_func('test', NULL); |
|||
|
|||
?> |
|||
--EXPECTF-- |
|||
ok |
|||
ok |
|||
|
|||
Catchable fatal error: Argument 1 passed to test() must be of the type boolean, null given in %s on line %d |
|||
@ -0,0 +1,22 @@ |
|||
--TEST-- |
|||
Parameter type hint - Testing default parameter values |
|||
--FILE-- |
|||
<?php |
|||
|
|||
function test(string $a, bool $b = NULL, integer $c, double $d = NULL, $e) { |
|||
print "ok\n"; |
|||
} |
|||
|
|||
test('foo', NULL, 1, NULL, 'bar'); |
|||
test('foo', true, 0, -1., NULL); |
|||
test('true', false, -1, 2.2222, 1.1); |
|||
test('1.1', false, -1, 11111111111111111111111111, true); |
|||
test('1', false, -1, NULL, new stdClass); |
|||
|
|||
?> |
|||
--EXPECT-- |
|||
ok |
|||
ok |
|||
ok |
|||
ok |
|||
ok |
|||
@ -0,0 +1,14 @@ |
|||
--TEST-- |
|||
Parameter type hint - Testing default parameter values as constants |
|||
--FILE-- |
|||
<?php |
|||
|
|||
function test(int $foo = PHP_INT_MAX) { |
|||
print "ok\n"; |
|||
} |
|||
|
|||
test(); |
|||
|
|||
?> |
|||
--EXPECT-- |
|||
ok |
|||
4996
Zend/zend_language_scanner.c
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
Write
Preview
Loading…
Cancel
Save
Reference in new issue