English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Basic PHP Tutorial

Advanced PHP Tutorial

PHP & MySQL

PHP Reference Manual

PHP property_exists() function usage and example

PHP Class/Object function reference manual

The property_exists() function checks whether an object or class has the specified property

Syntax

property_exists ($object, $property);

Definition and usage

This function checks whether the given property exists in the specified class (and whether it can be accessed from the current scope).

Parameter

NumberParameters and descriptions
1

object (required)

A string representation of a class name or an object of the class to be checked

2

property (required)

The name of the property.

Return value

If the property exists, it returns TRUE; if the property does not exist, it returns FALSE; if an error occurs, it returns NULL.

Online examples

The following is the usage of this function-

<?php
class myClass {
    public $mine;
    private $xpto;
    static protected $test;
    static function test() {
        var_dump(property_exists('myClass', 'xpto')); //true
    }
}
var_dump(property_exists('myClass', 'mine'));   //true
var_dump(property_exists(new myClass, 'mine')); //true
var_dump(property_exists('myClass', 'xpto'));   //true, from PHP 5.3From version .0
var_dump(property_exists('myClass', 'bar'));    //false
var_dump(property_exists('myClass', 'test'));   //true, from PHP 5.3From version .0
myClass::test();
?>

PHP Class/Object function reference manual