Rechercher une fonction PHP

property_exists

(PHP 5 >= 5.1.0, PHP 7)

property_exists Checks if the object or class has a property

Description

property_exists ( mixed $class , string $property ) : bool

This function checks if the given property exists in the specified class.

Note:

As opposed with isset(), property_exists() returns TRUE even if the property has the value NULL.

PHP: property_exists - Manual Home of Manuel PHP  Contents Haut

Parameters

class

The class name or an object of the class to test for

property

The name of the property

PHP: property_exists - Manual Home of Manuel PHP  Contents Haut

Return Values

Returns TRUE if the property exists, FALSE if it doesn't exist or NULL in case of an error.

PHP: property_exists - Manual Home of Manuel PHP  Contents Haut

Notes

Note:

Using this function will use any registered autoloaders if the class is not already known.

Note:

The property_exists() function cannot detect properties that are magically accessible using the __get magic method.

PHP: property_exists - Manual Home of Manuel PHP  Contents Haut

Changelog

Version Description
5.3.0 This function checks the existence of a property independent of accessibility.

PHP: property_exists - Manual Home of Manuel PHP  Contents Haut

Examples

Example #1 A property_exists() example

<?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, as of PHP 5.3.0
var_dump(property_exists('myClass''bar'));    //false
var_dump(property_exists('myClass''test'));   //true, as of PHP 5.3.0
myClass::test();

?>

PHP: property_exists - Manual Home of Manuel PHP  Contents Haut

See Also

Find a PHP function

English translation

You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.

If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.

Thank you in advance.

Document created the 30/01/2003, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/php-rf-function.property-exists.html

The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.

References

  1. View the html document Language of the document:fr Manuel PHP : http://php.net

These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.

Contents Haut