Skip to main content
PHPBasicsObjects

PHP Objects

By September 14, 2022No Comments

How do we create a generic object in PHP?

1
2
3
4
5
6
7
8
#1 Standard Way
$obj = new stdClass();

#2 Typecaste way
$obj = (object)[];

#3 An anonymous class
$obj = new class{};