|
| 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 | +$codes[3] = <<<EOT |
| 31 | +function foo() { return \$a[]; } |
| 32 | +foo(); |
| 33 | +EOT; |
| 34 | + |
| 35 | +$codes[4] = <<<EOT |
| 36 | +function bar(): never { return true; } |
| 37 | +bar(); |
| 38 | +EOT; |
| 39 | + |
| 40 | +foreach ($codes as $key => $code) { |
| 41 | + echo "\n--------------\nSnippet no. $key:\n--------------\n"; |
| 42 | + $code = escapeshellarg($code); |
| 43 | + echo `echo $code | "$php" -a`, "\n"; |
| 44 | +} |
| 45 | + |
| 46 | +echo "\nDone\n"; |
| 47 | +?> |
| 48 | +--EXPECT-- |
| 49 | +-------------- |
| 50 | +Snippet no. 1: |
| 51 | +-------------- |
| 52 | +Interactive shell |
| 53 | + |
| 54 | +php > function f($x): void { return $x; } |
| 55 | + |
| 56 | +Fatal error: A void function must not return a value in php shell code on line 1 |
| 57 | +php > f(1); |
| 58 | + |
| 59 | +Warning: Uncaught Error: Call to undefined function f() in php shell code:1 |
| 60 | +Stack trace: |
| 61 | +#0 {main} |
| 62 | + thrown in php shell code on line 1 |
| 63 | +php > |
| 64 | + |
| 65 | +-------------- |
| 66 | +Snippet no. 2: |
| 67 | +-------------- |
| 68 | +Interactive shell |
| 69 | + |
| 70 | +php > function f($x): void { return $x; } |
| 71 | + |
| 72 | +Fatal error: A void function must not return a value in php shell code on line 1 |
| 73 | +php > function f($x): int { return $x; } |
| 74 | +php > echo f(1); |
| 75 | +1 |
| 76 | +php > |
| 77 | + |
| 78 | +-------------- |
| 79 | +Snippet no. 3: |
| 80 | +-------------- |
| 81 | +Interactive shell |
| 82 | + |
| 83 | +php > function foo() { return $a[]; } |
| 84 | + |
| 85 | +Fatal error: Cannot use [] for reading in php shell code on line 1 |
| 86 | +php > foo(); |
| 87 | + |
| 88 | +Warning: Uncaught Error: Call to undefined function foo() in php shell code:1 |
| 89 | +Stack trace: |
| 90 | +#0 {main} |
| 91 | + thrown in php shell code on line 1 |
| 92 | +php > |
| 93 | + |
| 94 | +-------------- |
| 95 | +Snippet no. 4: |
| 96 | +-------------- |
| 97 | +Interactive shell |
| 98 | + |
| 99 | +php > function bar(): never { return true; } |
| 100 | + |
| 101 | +Fatal error: A never-returning function must not return in php shell code on line 1 |
| 102 | +php > bar(); |
| 103 | + |
| 104 | +Warning: Uncaught Error: Call to undefined function bar() in php shell code:1 |
| 105 | +Stack trace: |
| 106 | +#0 {main} |
| 107 | + thrown in php shell code on line 1 |
| 108 | +php > |
| 109 | + |
| 110 | +Done |
0 commit comments