Skip to content

How to create object in PHP wihtout class?

//You can use stdClass which is sort of empty template   
$object = new stdClass();

//Assign property
$object->property = 'Here we go';

//Now if we dump it
   object(stdClass)#2 (1) {
      string(10) "Here we go"
//Even shorter
$object = (object) ['property' => 'Here we go'];
See also  How to get input from list in Python?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.