• Objects

    An object in programming is like a container that holds things. It can be used to store information like a box can store toys. For example, we could create an object called "cat" and it could have different pieces of information inside it like the cat's name, its color, or even how many lives it has left. Objects help us keep track of all the pieces of information we need for a program.

      • Map, Dictionary, Variable Objects

      • <?php
        $person = (object)array(
        	'name' => 'John',
        	'age ' => 36
        );
        
        print($person['name']); // John
        print($person['age']); // 36
      • Class Objects

      • <?php
        class Person {
        	public $name, $age;
        
        	function __construct($name, $age) {
        		$this->name = $name;
        		$this->age = $age;
        	}
        
        	public function greet() {
        		print('Hello my name is ' . $this->name);
        	}
        }
        
        $human = new Person('John', 36);
        
        print($human->name); // John
        print($human->age); // 36
        $human->greet(); // Hello my name is John