ReflectionProperty::isVirtual

プロパティが仮想プロパティかどうかを判定する

説明

public bool ReflectionProperty::isVirtual()

プロパティが仮想プロパティかどうかを判定します。

パラメータ

この関数にはパラメータはありません。

戻り値

プロパティが仮想プロパティの場合 true を返します。 そうでない場合、false を返します。

例1 ReflectionProperty::isVirtual の例

<?php
class Example
{
    // どのフックもプロパティを参照していないので
    // これは仮想プロパティです
    public string $name { get => "Name here"; }

    // このフックはプロパティを名前で参照しているので
    // 仮想プロパティではありません
    public int $age {
        set {
            if ($value <= 0) {
               throw new \InvalidArgumentException();
            }
            $this->age = $value;
        }
    }

    // フックがないプロパティは常に仮想プロパティです
    public string $job;
}

$rClass = new \ReflectionClass(Example::class);

var_dump($rClass->getProperty('name')->isVirtual());
var_dump($rClass->getProperty('age')->isVirtual());
var_dump($rClass->getProperty('job')->isVirtual());
?>

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

bool(true)
bool(false)
bool(false)