Forum PHP 2025

ReflectionProperty::getRawValue

(PHP 8 >= 8.4.0)

ReflectionProperty::getRawValueget フックが定義されていたとしても、それを迂回してプロパティの値を返す

説明

public ReflectionProperty::getRawValue(object $object): mixed
警告

この関数は、 現在のところ詳細な情報はありません。引数のリストのみが 記述されています。

get フックが定義されていたとしても、それを迂回してプロパティの値を返します。

パラメータ

object
値を取得するオブジェクト

戻り値

プロパティに保存した値を返します。 その値は get フックが定義されていたとしても、 それを迂回したものになります。

エラー / 例外

プロパティが仮想プロパティだった場合、 Error がスローされます。 取得する実体の値が存在しないためです。

例1 ReflectionProperty::getRawValue() の例

<?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');

// getフックを経由した値なので、"php" を出力します。
echo $example->tag, PHP_EOL;
echo
$rProp->getValue($example), PHP_EOL;

// フックを迂回するので、"PHP" を出力します。
echo $rProp->getRawValue($example);

?>

上の例の出力は以下となります。

php
php
PHP
add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top