Skip to content

Commit 5182ef4

Browse files
committed
moar tests
1 parent 5fa2a41 commit 5182ef4

File tree

7 files changed

+74
-8
lines changed

7 files changed

+74
-8
lines changed

Zend/tests/return_hint/011.phpt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Basic return hints callable
3+
--FILE--
4+
<?php
5+
class foo {
6+
public function bar() : callable {
7+
return function() {};
8+
}
9+
}
10+
11+
$baz = new foo();
12+
var_dump($baz->bar());
13+
?>
14+
--EXPECTF--
15+
object(Closure)#%d (%d) {
16+
["this"]=>
17+
object(foo)#%d (0) {
18+
}
19+
}
20+
21+

Zend/tests/return_hint/012.phpt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
Basic return hints callable and closures
3+
--FILE--
4+
<?php
5+
class foo {
6+
public function bar() : callable {
7+
$test = "one";
8+
return function() use($test) : ?array {
9+
return array($test);
10+
};
11+
}
12+
}
13+
14+
$baz = new foo();
15+
var_dump($baz->bar());
16+
?>
17+
--EXPECT--
18+
object(Closure)#2 (2) {
19+
["static"]=>
20+
array(1) {
21+
["test"]=>
22+
string(3) "one"
23+
}
24+
["this"]=>
25+
object(foo)#1 (0) {
26+
}
27+
}

Zend/tests/return_hint/013.phpt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
Basic return hints callable and closures errors
3+
--FILE--
4+
<?php
5+
class foo {
6+
public function bar() : callable {
7+
$test = "one";
8+
return function() use($test) : array {
9+
return null;
10+
};
11+
}
12+
}
13+
14+
$baz = new foo();
15+
var_dump($func=$baz->bar(), $func());
16+
?>
17+
--EXPECT--
18+
Fatal error: the function {closure} was expected to return array and returned null in %s on line %d
19+

Zend/zend_compile.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1878,7 +1878,6 @@ void zend_do_function_return_hint(const znode *return_hint, zend_bool allow_null
18781878
CG(active_op_array)->return_hint.type = Z_TYPE(return_hint->u.constant);
18791879
}
18801880
} else {
1881-
printf("non constant return hint\n");
18821881
CG(active_op_array)->return_hint.type = IS_OBJECT;
18831882
CG(active_op_array)->return_hint.class_name_len = Z_STRLEN(return_hint->u.constant);
18841883
CG(active_op_array)->return_hint.class_name = zend_new_interned_string

Zend/zend_language_parser.y

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -862,10 +862,10 @@ expr_without_variable:
862862
| T_PRINT expr { zend_do_print(&$$, &$2 TSRMLS_CC); }
863863
| T_YIELD { zend_do_yield(&$$, NULL, NULL, 0 TSRMLS_CC); }
864864
| function is_reference { zend_do_begin_lambda_function_declaration(&$$, &$1, $2.op_type, 0 TSRMLS_CC); }
865-
'(' parameter_list ')' lexical_vars
865+
'(' parameter_list ')' lexical_vars function_return_hint
866866
'{' inner_statement_list '}' { zend_do_end_function_declaration(&$1 TSRMLS_CC); $$ = $3; }
867867
| T_STATIC function is_reference { zend_do_begin_lambda_function_declaration(&$$, &$2, $3.op_type, 1 TSRMLS_CC); }
868-
'(' parameter_list ')' lexical_vars
868+
'(' parameter_list ')' lexical_vars function_return_hint
869869
'{' inner_statement_list '}' { zend_do_end_function_declaration(&$2 TSRMLS_CC); $$ = $4; }
870870
;
871871

Zend/zend_vm_def.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2872,7 +2872,7 @@ ZEND_VM_HANDLER(62, ZEND_RETURN, CONST|TMP|VAR|CV, ANY)
28722872
"the function %s was expected to return callable and returned %s",
28732873
EX(function_state).function->common.function_name,
28742874
zend_get_type_by_const(Z_TYPE_P(retval_ptr)));
2875-
}
2875+
} break;
28762876

28772877
case IS_OBJECT: {
28782878
zend_class_entry **ce = NULL;

Zend/zend_vm_execute.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2618,7 +2618,7 @@ static int ZEND_FASTCALL ZEND_RETURN_SPEC_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARG
26182618
"the function %s was expected to return callable and returned %s",
26192619
EX(function_state).function->common.function_name,
26202620
zend_get_type_by_const(Z_TYPE_P(retval_ptr)));
2621-
}
2621+
} break;
26222622

26232623
case IS_OBJECT: {
26242624
zend_class_entry **ce = NULL;
@@ -8026,7 +8026,7 @@ static int ZEND_FASTCALL ZEND_RETURN_SPEC_TMP_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
80268026
"the function %s was expected to return callable and returned %s",
80278027
EX(function_state).function->common.function_name,
80288028
zend_get_type_by_const(Z_TYPE_P(retval_ptr)));
8029-
}
8029+
} break;
80308030

80318031
case IS_OBJECT: {
80328032
zend_class_entry **ce = NULL;
@@ -13334,7 +13334,7 @@ static int ZEND_FASTCALL ZEND_RETURN_SPEC_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
1333413334
"the function %s was expected to return callable and returned %s",
1333513335
EX(function_state).function->common.function_name,
1333613336
zend_get_type_by_const(Z_TYPE_P(retval_ptr)));
13337-
}
13337+
} break;
1333813338

1333913339
case IS_OBJECT: {
1334013340
zend_class_entry **ce = NULL;
@@ -30997,7 +30997,7 @@ static int ZEND_FASTCALL ZEND_RETURN_SPEC_CV_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
3099730997
"the function %s was expected to return callable and returned %s",
3099830998
EX(function_state).function->common.function_name,
3099930999
zend_get_type_by_const(Z_TYPE_P(retval_ptr)));
31000-
}
31000+
} break;
3100131001

3100231002
case IS_OBJECT: {
3100331003
zend_class_entry **ce = NULL;

0 commit comments

Comments
 (0)