# OOP
## House Analogy
* Object: The house, itself, is the object.
* Class: The blueprints for the house.
* Properties: Color, shape, number of windows, etc.
* Methods: Build house, heat house, sell house, actions, etc.
* Instantiation: The construction.
## Car
* Object: The car.
* Class: The model of car
* Properties: Color, engine size, wheels
* Methods: Start car, drive car, turn, etc
* Instantiation: Create car.
## Examples
```php
ini_set( 'display_errors', '1' );
// Public - Can access from class, child class, or on the variable assignment after instantiaion.
// Protected - Can access only from class or child class.
// Private - Can access only from class.
// Final - Cannot override in child class.
// Static - Can call method or variable without having to instantiate class. Older method, we use namespaces now. // MyClass::$variable;
class MyClass {
protected $var = 'I like OOP';
static $testing = '12345';
public function __construct($text) {
$this->var = $text;
}
protected function my_function() {
echo $this->var;
}
}
class NewClass extends MyClass {
public function __construct($any) { // Pass in our variables if any.
parent::__construct($any); // Run the parent constructor.
}
public function my_function() {
echo 'Override';
}
public function test() {
echo $this->var;
}
}
$new = new NewClass('protected');
echo MyClass::$testing;
```