Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

stdclass

Stdclass is a native PHP class. It is the class used when a generic object is created, for example with json_decode() or the (object) cast operator.

The stdClass is allowed to create dynamic properties on the fly, as its base definition has none.

<?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