CakeFest 2025 Madrid: The Official CakePHP Conference

ReflectionProperty::isVirtual

(PHP 8 >= 8.4.0)

ReflectionProperty::isVirtualDetermines if a property is virtual

Description

public ReflectionProperty::isVirtual(): bool

Determines if a property is virtual.

Parameters

This function has no parameters.

Return Values

Returns true if the property is virtual, false otherwise.

Examples

Example #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());
?>

The above example will output:

bool(true)
bool(false)
bool(false)
add a note

User Contributed Notes

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

Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant