Anthony Nach PHP-Handbuch:
In PHP 7 gibt es ein paar Möglichkeiten, um ein leeres Objekt zu erstellen:
<?php
$obj1 = new \stdClass; // Instantiate stdClass object
$obj2 = new class{}; // Instantiate anonymous class
$obj3 = (object)[]; // Cast empty array to object
var_dump($obj1); // object(stdClass)#1 (0) {}
var_dump($obj2); // object([email protected])#2 (0) {}
var_dump($obj3); // object(stdClass)#3 (0) {}
?>
Für mehr auf das, was er zu sagen hatte besuchen PHP Manual documentation mit seiner Antwort.
auf seine Antwort zu erweitern, die erste würde wie folgt aussehen:
Erstes Beispiel
$obj1 = new \stdClass;
$obj1->first = 1;
print_r($obj1);
// output
// stdClass Object
// (
// [first] => 1
//)
Zweites Beispiel
$obj2 = new class{ };
$obj2->second = 2;
print_r($obj2);
// output
// [email protected] Object
// (
// [second] => 2
//)
Drittes Beispiel
$obj3 = (object)[];
$obj3->third = 3;
print_r($obj3);
// output
// stdClass Object
// (
// [third] => 3
//)
Sie könnte tue etwas in dieser Richtung; es ist so einfach wie das
Schauen Sie sich die Seite PHP [Objekte] (http://php.net/manual/en/language.types.object.php) an ... – War10ck
'$ obj = new stdClass(); $ obj-> item1 = 1; $ obj-> item2 = 2; ' –