examples of objects in php

Example 1: php create object

$x = (object) [
    'a' => 'test',
    'b' => 'test2',
    'c' => 'test3'
];
var_dump($x);

/*
object(stdClass)#1 (3) {
  ["a"]=>
  string(4) "test"
  ["b"]=>
  string(5) "test2"
  ["c"]=>
  string(5) "test3"
}
*/

Example 2: php define object

$x = new stdClass();

Example 3: php object

$o= new \stdClass();
$o->a = 'new object';

OR

$o = (object) ['a' => 'new object'];

Example 4: oops concepts in php

The  PHP Object-Oriented Programming concepts are:
Class 
Objects
Inheritance
Interface
Abstraction
Magic Methods

Tags:

Php Example