1$x = (object) [
2 'a' => 'test',
3 'b' => 'test2',
4 'c' => 'test3'
5];
6var_dump($x);
7
8/*
9object(stdClass)#1 (3) {
10 ["a"]=>
11 string(4) "test"
12 ["b"]=>
13 string(5) "test2"
14 ["c"]=>
15 string(5) "test3"
16}
17*/
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<?php
2class Fruit {
3 public $name;
4 public $color;
5
6 function __construct($name, $color) {
7 $this->name = $name;
8 $this->color = $color;
9 }
10 function get_name() {
11 return $this->name;
12 }
13 function get_color() {
14 return $this->color;
15 }
16}
17
18$apple = new Fruit("Apple", "red");
19echo $apple->get_name();
20echo "<br>";
21echo $apple->get_color();
22?>
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?>