File: 0006-uopz-opcache-const-subst.phpt

package info (click to toggle)
php-uopz 7.1.1%2B%2B-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 688 kB
  • sloc: ansic: 2,137; xml: 335; makefile: 2
file content (52 lines) | stat: -rw-r--r-- 1,201 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
--TEST--
opcache constant substitution disable
--EXTENSIONS--
uopz
--SKIPIF--
<?php
	uopz_allow_exit(true);
	$opcache = ini_get("opcache.enable_cli");
	if ($opcache === false || $opcache === "0") die("skip opcache required");

    $protect = extension_loaded("Zend OPcache")
        && ($conf = opcache_get_configuration()["directives"])
        && array_key_exists("opcache.protect_memory", $conf)
        &&  $conf["opcache.protect_memory"];
    if ($protect) die("xfail known issues with constant redefinition; see #151");
?>
--INI--
uopz.disable=0
opcache.enabled=1
opcache.enable_cli=1
opcache.optimization_level=0x7FFFBFFF
--FILE--
<?php
class Foo {
    const USE_B = false;
 
    public function __call ($method, $arguments) {
        return self::USE_B ? $this->callB () : $this->callA ();
    }
 
    private function callA () {
        echo "A!" . PHP_EOL;
    }
    private function callB () {
        echo "B!" . PHP_EOL;
    }
}
 
uopz_set_return (Foo::class, 'callA', function () { echo "uopz A!" . PHP_EOL; }, true);
 
$x = new Foo;
var_dump ($x->__call (null, null));
 
uopz_redefine (Foo::class, 'USE_B', true);
var_dump ($x->__call (null, null));
?>
--EXPECT--
uopz A!
NULL
B!
NULL