File tree 2 files changed +75
-2
lines changed
2 files changed +75
-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
+ if (!extension_loaded ('readline ' ) || readline_info ('done ' ) === NULL ) {
7
+ die ("skip need readline support " );
8
+ }
9
+ ?>
10
+ --FILE--
11
+ <?php
12
+ $ php = getenv ('TEST_PHP_EXECUTABLE ' );
13
+
14
+ // disallow console escape sequences that may break the output
15
+ putenv ('TERM=VT100 ' );
16
+
17
+ $ codes = array ();
18
+
19
+ $ codes [1 ] = <<<EOT
20
+ function f( \$x): void { return \$x; }
21
+ f(1);
22
+ EOT ;
23
+
24
+ $ codes [2 ] = <<<EOT
25
+ function f( \$x): void { return \$x; }
26
+ function f( \$x): int { return \$x; }
27
+ echo f(1);
28
+ EOT ;
29
+
30
+ foreach ($ codes as $ key => $ code ) {
31
+ echo "\n-------------- \nSnippet no. $ key: \n-------------- \n" ;
32
+ $ code = escapeshellarg ($ code );
33
+ echo `echo $ code | " $ php" -a `, "\n" ;
34
+ }
35
+
36
+ echo "\nDone \n" ;
37
+ ?>
38
+ --EXPECT--
39
+ --------------
40
+ Snippet no. 1:
41
+ --------------
42
+ Interactive shell
43
+
44
+ php > function f($x): void { return $x; }
45
+
46
+ Fatal error: A void function must not return a value in php shell code on line 1
47
+ php > f(1);
48
+
49
+ Warning: Uncaught Error: Call to undefined function f() in php shell code:1
50
+ Stack trace:
51
+ #0 {main}
52
+ thrown in php shell code on line 1
53
+ php >
54
+
55
+ --------------
56
+ Snippet no. 2:
57
+ --------------
58
+ Interactive shell
59
+
60
+ php > function f($x): void { return $x; }
61
+
62
+ Fatal error: A void function must not return a value in php shell code on line 1
63
+ php > function f($x): int { return $x; }
64
+ php > echo f(1);
65
+ 1
66
+ php >
67
+
68
+ Done
You can’t perform that action at this time.
0 commit comments