Friday, February 6, 2026
HomeLanguagesPHP ReflectionClass hasProperty() Function

PHP ReflectionClass hasProperty() Function

The ReflectionClass hasProperty() function is an inbuilt function in PHP that is used to check the specified property is present or not.
 

Syntax: 

bool ReflectionClass hasProperty( string $name )

Parameters: This function accepts a single parameter $name which holds the name of the property that is being checked.
Return Value: This function returns true if the specified property is present, otherwise returns false.
Below programs illustrate the ReflectionClass hasProperty() function in PHP:
 

Program 1: 

php




<?php
 
// Using ReflectionClass
$ReflectionClass = new ReflectionClass('ReflectionClass');
 
// Initializing a property name
$a = 'name';
 
// Calling hasProperty() function over
// the property name
$Property = $ReflectionClass->hasProperty($a);
 
// Getting the value true or false
var_dump($Property);
?>


Output: 

bool(true)

 

Program 2: 

php




<?php
  
// Defining a user-defined class Company
class Company {
    Public Function neveropen() {}
    Private Function GFG() {}
}
  
// Using ReflectionClass over the above
// Company class
$Class = new ReflectionClass('Company');
  
// Calling hasProperty() function
$A = $Class->hasProperty($Class);
  
// Getting the value either true or false
var_dump($A);
?>


Output: 

bool(false)

 

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

RELATED ARTICLES

Most Popular

Dominic
32489 POSTS0 COMMENTS
Milvus
126 POSTS0 COMMENTS
Nango Kala
6862 POSTS0 COMMENTS
Nicole Veronica
11983 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12073 POSTS0 COMMENTS
Shaida Kate Naidoo
6995 POSTS0 COMMENTS
Ted Musemwa
7236 POSTS0 COMMENTS
Thapelo Manthata
6946 POSTS0 COMMENTS
Umr Jansen
6930 POSTS0 COMMENTS