Dynamic Properties

Dynamic properties are properties created on the fly, without previous definition.

When the class implements the magic methods __get() and __set(), of if the class extends stdClass, then no warning is emitted.

<?php

    class X {
        private $property = 1;

        function foo() {
            // dynamic property
            $this->a = 1;

            // dynamic property with variable name
            $b = 'abc';
            $this->$b = 1;

            // static property
            $this->property = 1;
        }
    }

?>

Documentation

See also PHP, what are dynamic properties? and PHP’s Dynamic Properties RFC: A Case of Solving the Wrong Problem.

Related : Properties, Magic Methods, stdclass, Dynamic, Var