In PHP, you can initialize arrays with values quickly using the following notation:
$array = array(\"name\" => \"member 1\", array(\"name\" => \"member
from this answer to a similar question:
As of PHP7, we have Anonymous Classes which would allow you to extend a class at runtime, including setting of additional properties:
$a = new class() extends MyObject {
public $property1 = 1;
public $property2 = 2;
};
echo $a->property1; // prints 1
It's not as succinct as the initializer for array. Not sure if I'd use it. But it is another option you can consider.
You can use :
$object = (object)[]; // shorter version of (object)array();
$object->foo = 'bar';