PHP.nl

uopz_flags

uopz_flags

Get or set flags on function or class

int **uopz_flags** string $function int $flags
int **uopz_flags** string $class string $function int $flags

Get or set the flags on a class or function entry at runtime

classThe name of a class

function The name of the function. If is given and an empty string is passed as , gets or sets the flags of the class entry. class``function``uopz_flags

flags A valid set of ZEND_ACC_ flags. If omitted, acts as getter. uopz_flags

If setting, returns old flags, else returns flags

As of PHP 7.4.0, if the parameter is passed, throws a , if is enabled, and the class entry of or the function entry of is immutable. flags``uopz_flags``RuntimeExceptionOPcacheclass``function

Voorbeeld: example

<?php
class Test {
    public function method() {
        return __CLASS__;
    }
}

$flags = uopz_flags("Test", "method");

var_dump((bool) (uopz_flags("Test", "method") & ZEND_ACC_PRIVATE));
var_dump((bool) (uopz_flags("Test", "method") & ZEND_ACC_STATIC));

var_dump(uopz_flags("Test", "method", $flags|ZEND_ACC_STATIC|ZEND_ACC_PRIVATE));

var_dump((bool) (uopz_flags("Test", "method") & ZEND_ACC_PRIVATE));
var_dump((bool) (uopz_flags("Test", "method") & ZEND_ACC_STATIC));
?>
bool(false)
bool(false)
int(1234567890)
bool(true)
bool(true)

Voorbeeld: "Unfinalize" a Class

<?php
final class MyClass
{
}

$flags = uopz_flags(MyClass::class, '');
uopz_flags(MyClass::class, '', $flags & ~ZEND_ACC_FINAL);
var_dump((new ReflectionClass(MyClass::class))->isFinal());
?>
bool(false)