__isset() Method

__isset() is a magic method: it is called when the existence of a property has to be checked.

That way, it is possible to create dynamically properties, without hardcoding them.

The __isset() method is usually paired with the __get() and __set() methods.

The __isset() is called by isset() and empty(). They are also called by the coalesce operator ?? and ??=. It is not called on null-safe object opeartor ?->.

<?php

    class X {
        private $values = ['a' => 1,
                           'b' => 2,
                           ];

        function __isset($name) {
            return isset($this->values[$name]);
        }
    }

    $x = new X;
    var_dump(isset($x->a)); // true
    var_dump(empty($x->c)); // false

?>

Documentation

See also A Look At PHP’s isset().

Related : Magic Methods, __set() Method, __get() Method, __unset() Method, Isset, Null, Null Safe Object Operator, Magic Property