php8.5
Home/ Manual/ reflection / reflectionproperty/ ReflectionProperty::getRawValue

ReflectionProperty::getRawValue

PHP function Edit on GitHub ✎

(PHP 8 >= 8.4.0)

Returns the value of a property, bypassing a get hook if defined

Description

ReflectionProperty::getRawValue(object $object): mixed

Func

Returns the value of a property, bypassing a get hook if defined.

Parameters

object

The object from which to retrieve a value.

Return Values

The stored value of the property, bypassing a get hook if defined.

Errors/Exceptions

If the property is virtual, an Error will be thrown, as there is no raw value to retrieve.

Examples

ReflectionProperty::getRawValue example

php
<?php

class Example
{
    public string $tag {
        get => strtolower($this->tag);
    }
}

$example = new Example();
$example->tag = 'PHP';

$rClass = new \ReflectionClass(Example::class);
$rProp = $rClass->getProperty('tag');

// These would go through the get hook, so would produce "php"
echo $example->tag, PHP_EOL;
echo $rProp->getValue($example), PHP_EOL;

// But this would bypass the hook and produce "PHP"
echo $rProp->getRawValue($example);

?>

The above example will output:

output
php
php
PHP

See Also

Source: reference/reflection/reflectionproperty/getrawvalue.xml · from the official PHP manual (php/doc-en)