Friday, October 17, 2025
HomeLanguagesPHP | ReflectionClass isAnonymous() Function

PHP | ReflectionClass isAnonymous() Function

The ReflectionClass::isAnonymous() function is an inbuilt function in PHP which is used to check the specified class is anonymous or not.

Syntax:

bool ReflectionClass::isAnonymous( void )

Parameters: This function does not accept any parameters.

Return Value: This function returns True on success or False otherwise.

Below programs illustrate the ReflectionClass::isAnonymous() function in PHP:

Program 1:




<?php
  
// Initialising an anonymous class
$anonymousClass = new class {};
  
// Using ReflectionClass over the anonymous class
$A = new ReflectionClass($anonymousClass);
  
// Calling the isAnonymous() function
$B = $A->isAnonymous();
  
// Getting the value true or false
var_dump($B);
?>


Output:

bool(true)

Program 2:




<?php
  
// Defining a user-defined class Company
class Company {
    private function neveropen() {}
    private function GFG() {}
}
  
// Using ReflectionClass over the
// Company class
$A = new ReflectionClass('Company');
  
// Calling the isAnonymous() function
$B = $A->isAnonymous();
  
// Getting the value true or false
var_dump($B);
?>


Output:

bool(false)

Reference: https://www.php.net/manual/en/reflectionclass.isanonymous.php

RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS