File tree 2 files changed +72
-2
lines changed
2 files changed +72
-2
lines changed Original file line number Diff line number Diff line change @@ -4794,8 +4794,13 @@ void zend_compile_return(zend_ast *ast) /* {{{ */
4794
4794
4795
4795
/* Generator return types are handled separately */
4796
4796
if (!is_generator && (CG (active_op_array )-> fn_flags & ZEND_ACC_HAS_RETURN_TYPE )) {
4797
- zend_emit_return_type_check (
4798
- expr_ast ? & expr_node : NULL , CG (active_op_array )-> arg_info - 1 , 0 );
4797
+ zend_try {
4798
+ zend_emit_return_type_check (
4799
+ expr_ast ? & expr_node : NULL , CG (active_op_array )-> arg_info - 1 , 0 );
4800
+ } zend_catch {
4801
+ zend_hash_del (CG (function_table ), CG (active_op_array )-> function_name );
4802
+ zend_bailout ();
4803
+ } zend_end_try ();
4799
4804
}
4800
4805
4801
4806
zend_handle_loops_and_finally ((expr_node .op_type & (IS_TMP_VAR | IS_VAR )) ? & expr_node : NULL );
Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ GH-8841: Fix invalid return type compilation doesn't register function
3
+ --SKIPIF--
4
+ <?php
5
+ include "skipif.inc " ;
6
+ ?>
7
+ --FILE--
8
+ <?php
9
+ $ php = getenv ('TEST_PHP_EXECUTABLE ' );
10
+
11
+ // disallow console escape sequences that may break the output
12
+ putenv ('TERM=VT100 ' );
13
+
14
+ $ codes = array ();
15
+
16
+ $ codes [1 ] = <<<EOT
17
+ function f( \$x): void { return \$x; }
18
+ f(1);
19
+ EOT ;
20
+
21
+ $ codes [2 ] = <<<EOT
22
+ function f( \$x): void { return \$x; }
23
+ function f( \$x): int { return \$x; }
24
+ echo f(1);
25
+ EOT ;
26
+
27
+ foreach ($ codes as $ key => $ code ) {
28
+ echo "\n-------------- \nSnippet no. $ key: \n-------------- \n" ;
29
+ $ code = escapeshellarg ($ code );
30
+ echo `echo $ code | " $ php" -a `, "\n" ;
31
+ }
32
+
33
+ echo "\nDone \n" ;
34
+ ?>
35
+ --EXPECT--
36
+ --------------
37
+ Snippet no. 1:
38
+ --------------
39
+ Interactive shell
40
+
41
+ php > function f($x): void { return $x; }
42
+
43
+ Fatal error: A void function must not return a value in php shell code on line 1
44
+ php > f(1);
45
+
46
+ Warning: Uncaught Error: Call to undefined function f() in php shell code:1
47
+ Stack trace:
48
+ #0 {main}
49
+ thrown in php shell code on line 1
50
+ php >
51
+
52
+ --------------
53
+ Snippet no. 2:
54
+ --------------
55
+ Interactive shell
56
+
57
+ php > function f($x): void { return $x; }
58
+
59
+ Fatal error: A void function must not return a value in php shell code on line 1
60
+ php > function f($x): int { return $x; }
61
+ php > echo f(1);
62
+ 1
63
+ php >
64
+
65
+ Done
You can’t perform that action at this time.
0 commit comments