Browse Source
Added support for numeric & scalar type hint as defined within
Added support for numeric & scalar type hint as defined within
http://wiki.php.net/rfc/typecheckingstrictandweak RFCexperimental/lemon
11 changed files with 2060 additions and 1660 deletions
-
37Zend/tests/hint/param_type_hint_019.phpt
-
15Zend/tests/hint/param_type_hint_020.phpt
-
46Zend/tests/hint/param_type_hint_021.phpt
-
2Zend/zend.h
-
4Zend/zend_API.c
-
13Zend/zend_compile.c
-
12Zend/zend_execute.c
-
8Zend/zend_language_parser.y
-
3565Zend/zend_language_scanner.c
-
16Zend/zend_language_scanner.l
-
2Zend/zend_language_scanner_defs.h
@ -0,0 +1,37 @@ |
|||
--TEST-- |
|||
Parameter type hint - scalar type hints |
|||
--FILE-- |
|||
<?php |
|||
|
|||
function x($error, $msg) { var_dump($msg); } |
|||
set_error_handler('x', E_RECOVERABLE_ERROR); |
|||
|
|||
function foo(scalar $param) { var_dump($param); } |
|||
|
|||
foo(1); |
|||
foo(true); |
|||
foo(NULL); |
|||
foo(array(1)); |
|||
foo("foo"); |
|||
foo(111.222); |
|||
foo(new Stdclass); |
|||
foo(tmpfile()); |
|||
|
|||
?> |
|||
--EXPECTF-- |
|||
int(1) |
|||
bool(true) |
|||
string(%d) "Argument 1 passed to foo() must be of the type scalar, null given, called in %s on line %d and defined" |
|||
NULL |
|||
string(%d) "Argument 1 passed to foo() must be of the type scalar, array given, called in %s on line %d and defined" |
|||
array(1) { |
|||
[0]=> |
|||
int(1) |
|||
} |
|||
string(3) "foo" |
|||
float(111.222) |
|||
string(%d) "Argument 1 passed to foo() must be of the type scalar, object given, called in %s on line %d and defined" |
|||
object(stdClass)#1 (0) { |
|||
} |
|||
string(%d) "Argument 1 passed to foo() must be of the type scalar, resource given, called in %s on line %d and defined" |
|||
resource(4) of type (stream) |
|||
@ -0,0 +1,15 @@ |
|||
--TEST-- |
|||
Parameter type hint - scalar type hints, default value |
|||
--FILE-- |
|||
<?php |
|||
|
|||
function bar1(scalar $param = null) {} |
|||
function bar2(scalar $param = 123) {} |
|||
function bar3(scalar $param = false) {} |
|||
function bar4(scalar $param = 988.99) {} |
|||
function bar5(scalar $param = "1233") {} |
|||
function bar6(scalar $param = array(1,2,3)) {} |
|||
|
|||
?> |
|||
--EXPECTF-- |
|||
Fatal error: Default value for parameters with scalar type hint can only be scalar or NULL in %s on line %d |
|||
@ -0,0 +1,46 @@ |
|||
--TEST-- |
|||
Parameter type hint - numeric type hints |
|||
--FILE-- |
|||
<?php |
|||
|
|||
function x($error, $msg) { var_dump($msg); } |
|||
set_error_handler('x', E_RECOVERABLE_ERROR); |
|||
|
|||
function foo(numeric $param) { var_dump($param); } |
|||
|
|||
foo(1); |
|||
foo(true); |
|||
foo(NULL); |
|||
foo(array(1)); |
|||
foo("foo"); |
|||
foo("123.33"); |
|||
foo("123"); |
|||
foo(""); |
|||
foo(111.222); |
|||
foo(new Stdclass); |
|||
foo(tmpfile()); |
|||
|
|||
?> |
|||
--EXPECTF-- |
|||
int(1) |
|||
string(%d) "Argument 1 passed to foo() must be of the type numeric, boolean given, called in %s on line %d and defined" |
|||
bool(true) |
|||
string(%d) "Argument 1 passed to foo() must be of the type numeric, null given, called in %s on line %d and defined" |
|||
NULL |
|||
string(%d) "Argument 1 passed to foo() must be of the type numeric, array given, called in %s on line %d and defined" |
|||
array(1) { |
|||
[0]=> |
|||
int(1) |
|||
} |
|||
string(%d) "Argument 1 passed to foo() must be of the type numeric, string given, called in %s on line %d and defined" |
|||
string(3) "foo" |
|||
string(6) "123.33" |
|||
string(3) "123" |
|||
string(%d) "Argument 1 passed to foo() must be of the type numeric, string given, called in %s on line %d and defined" |
|||
string(0) "" |
|||
float(111.222) |
|||
string(%d) "Argument 1 passed to foo() must be of the type numeric, object given, called in %s on line %d and defined" |
|||
object(stdClass)#1 (0) { |
|||
} |
|||
string(%d) "Argument 1 passed to foo() must be of the type numeric, resource given, called in %s on line %d and defined" |
|||
resource(4) of type (stream) |
|||
3565
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