As we know, creating anonymous objects in JavaScript is easy, like the code below:
var object = {
p : \"value\",
p1 : [ \"john\", \"johnny\" ]
};
Support for anonymous classes has been available since PHP 7.0, and is the closest analogue to the JavaScript example provided in the question.
p1[1];
The visibility declaration on properties cannot be omitted (I just used var
because it's shorter than public
.)
Like JavaScript, you can also define methods for the class:
p;}
};
echo $object->foo();