Determines if a property is virtual

# ReflectionProperty::isVirtual

(PHP 8 >= 8.4.0)

ReflectionProperty::isVirtual — Determines if a property is virtual

### 说明

public function ReflectionProperty::isVirtual(): bool

Determines if a property is virtual.

### 参数

此函数没有参数。

### 返回值

Returns `true` if the property is virtual, `false` otherwise.

### 示例

示例 #1 ReflectionProperty::isVirtual() example

    <?php
    class Example
    {
        // None of the hooks reference the property,
        // so this is virtual.
        public string $name { get => "Name here"; }

        // This hook references the property by name,
        // so it is not virtual.
        public int $age {
            set {
                if ($value <= 0) {
                   throw new \InvalidArgumentException();
                }
                $this->age = $value;
            }
        }

        // Non-hooked properties are always not-virtual.
        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)

### 参见

- Virtual properties

`↑` and `↓` to navigate • `Enter` to select • `Esc` to close • `/` to open