1//create a person object in PHP
2$person=new stdClass();
3$person->firstName="Chuck";
4$person->lastName="Bartowski";
5$person->age=27;
6
7print_r($person);
8
9
1 $object = new stdClass();
2 $object->property = 'Here we go';
3
4 var_dump($object);
5 /*
6 outputs:
7
8 object(stdClass)#2 (1) {
9 ["property"]=>
10 string(10) "Here we go"
11 }
12 */
1//object init
2 $object = (object) [
3 'propertyOne' => 'foo',
4 'propertyTwo' => 42,
5 ];
1<?php
2class Bike
3{
4 function model()
5 {
6 $model_name = 'cd100';
7 echo "bike model:$model_name";
8 }
9}
10$obj = new Bike();
11$obj->model();
12?>
1$o= new \stdClass();
2$o->a = 'new object';
3
4OR
5
6$o = (object) ['a' => 'new object'];