Skip to content

Commit e1142bb

Browse files
committed
Disallow nullable mixed types at compile time
1 parent 336ca09 commit e1142bb

File tree

6 files changed

+1457
-0
lines changed

6 files changed

+1457
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--TEST--
2+
Test nullable mixed parameter type.
3+
--FILE--
4+
<?php
5+
6+
function test(?mixed $arg) {
7+
}
8+
9+
--EXPECTF--
10+
Fatal error: Mixed type cannot be nullable in %smixed_nullable_parameter.php on line %d
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--TEST--
2+
Test nullable mixed return type.
3+
--FILE--
4+
<?php
5+
6+
function test($arg): ?mixed {
7+
}
8+
9+
--EXPECTF--
10+
Fatal error: Mixed type cannot be nullable in %smixed_nullable_return.php on line %d

Zend/zend_compile.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5441,6 +5441,10 @@ void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast) /* {{{ */
54415441
zend_error_noreturn(E_COMPILE_ERROR, "Void type cannot be nullable");
54425442
}
54435443

5444+
if (ZEND_TYPE_CODE(arg_infos->type) == IS_MIXED && ZEND_TYPE_ALLOW_NULL(arg_infos->type)) {
5445+
zend_error_noreturn(E_COMPILE_ERROR, "Mixed type cannot be nullable");
5446+
}
5447+
54445448
arg_infos++;
54455449
op_array->fn_flags |= ZEND_ACC_HAS_RETURN_TYPE;
54465450
} else {
@@ -5535,6 +5539,10 @@ void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast) /* {{{ */
55355539
zend_error_noreturn(E_COMPILE_ERROR, "void cannot be used as a parameter type");
55365540
}
55375541

5542+
if (ZEND_TYPE_CODE(arg_info->type) == IS_MIXED && ZEND_TYPE_ALLOW_NULL(arg_info->type)) {
5543+
zend_error_noreturn(E_COMPILE_ERROR, "Mixed type cannot be nullable");
5544+
}
5545+
55385546
if (type_ast->kind == ZEND_AST_TYPE) {
55395547
if (ZEND_TYPE_CODE(arg_info->type) == IS_ARRAY) {
55405548
if (default_ast && !has_null_default

errors.log

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[06-Jul-2017 21:06:40 UTC] PHP Deprecated: Directive 'track_errors' is deprecated in Unknown on line 0

0 commit comments

Comments
 (0)