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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
--TEST--
uopz_set_static
--EXTENSIONS--
uopz
--INI--
uopz.disable=0
--FILE--
<?php
class Foo {
public function method() {
static $vars = [
1,2,3,4,5];
$vars[] = 6;
}
public function nostatics() {}
}
function nostatics() {}
$foo = new Foo();
$foo->method();
var_dump(uopz_get_static(Foo::class, "method"));
uopz_set_static(Foo::class, "method", [
"vars" => []
]);
$foo->method();
var_dump(uopz_get_static(Foo::class, "method"));
try {
uopz_set_static(Foo::class, "none", []);
} catch(RuntimeException $ex) {
var_dump($ex->getMessage());
}
try {
uopz_set_static("none", []);
} catch(RuntimeException $ex) {
var_dump($ex->getMessage());
}
try {
uopz_set_static("phpversion", []);
} catch(RuntimeException $ex) {
var_dump($ex->getMessage());
}
try {
uopz_set_static(DateTime::class, "__construct", []);
} catch(RuntimeException $ex) {
var_dump($ex->getMessage());
}
try {
uopz_set_static(Foo::class, "nostatics", []);
} catch(RuntimeException $ex) {
var_dump($ex->getMessage());
}
try {
uopz_set_static("nostatics", []);
} catch(RuntimeException $ex) {
var_dump($ex->getMessage());
}
?>
--EXPECTF--
array(1) {
["vars"]=>
array(6) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
[3]=>
int(4)
[4]=>
int(5)
[5]=>
int(6)
}
}
array(1) {
["vars"]=>
array(1) {
[0]=>
int(6)
}
}
string(%d) "failed to set statics in method %s::%s, it does not exist"
string(%d) "failed to set statics in function %s, it does not exist"
string(%d) "failed to set statics in internal function %s"
string(%d) "failed to set statics in internal method %s::%s"
string(%d) "failed to set statics in method %s::%s, no statics declared"
string(%d) "failed to set statics in function %s, no statics declared"
|