Avatar ·

How to create an object in PHP without declaring a class?

Hi everyone! I just started learning PHP and encountered this situation. In other languages, like JavaScript, I can write something like:\n\n```javascript\nlet person = { name: "John", age: 30 };\n```\n\nThat is, create an object on the fly without predefining a class. In Python there are also dictionaries and `namedtuple`, but in PHP I see that you usually need to declare a class first:\n\n```php\nclass Person {\n public $name;\n public $age;\n}\n$person = new Person();\n$person->name = "John";\n```\n\nBut this is terribly inconvenient for simple data structures! Imagine I need to pass a configuration with 10 fields to a function — do I really have to write a class every time? I came across old forums where they recommend using `stdClass`, but I don't quite understand how it works. Is it possible to create an object without a cl