xref: /PHP-7.4/ext/opcache/tests/ssa_bug_003.phpt (revision 75bc3446)
1--TEST--
2Incorrect elision of return type checks
3--SKIPIF--
4<?php require_once('skipif.inc'); ?>
5--FILE--
6<?php
7
8function test1($x) : callable {
9    if ($x == 1) {
10        $c = 'foo';
11    } elseif ($x == 2) {
12        $c = new stdClass;
13    } else {
14        $c = [$x => &$x];
15    }
16    return $c;
17}
18
19try {
20    test1(1);
21} catch (Error $e) {
22    echo "Error: {$e->getMessage()}\n";
23}
24
25class Foo {}
26function test2() : Foo {
27    $obj = new stdClass;
28    return $obj;
29}
30
31try {
32    test2();
33} catch (Error $e) {
34    echo "Error: {$e->getMessage()}\n";
35}
36
37?>
38--EXPECT--
39Error: Return value of test1() must be callable, string returned
40Error: Return value of test2() must be an instance of Foo, instance of stdClass returned
41