php8.5
Home/ Manual/ reflection / reflectionclass/ ReflectionClass::isAnonymous

ReflectionClass::isAnonymous

PHP function Edit on GitHub ✎

(PHP 7, PHP 8)

Checks if class is anonymous

Description

ReflectionClass::isAnonymous(): bool

Checks if a class is an anonymous class.

Parameters Parameters

Return Values

Returns true if the class is anonymous or false otherwise.

Examples

ReflectionClass::isAnonymous example

php
<?php
class TestClass {}
$anonClass = new class {};

$normalClass = new ReflectionClass('TestClass');
$anonClass  = new ReflectionClass($anonClass);

var_dump($normalClass->isAnonymous());
var_dump($anonClass->isAnonymous());

?>

The above example will output:

output
bool(false)
bool(true)

See Also

  • ReflectionClass::isFinal

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