What is the difference between two codes?
Extends;
<?php
require_once 'example.class.php';
Class First extends Example
{}
?>
Normal calling;
<?php
require_once 'example.class.php';
Class First
{
public $example;
function __construct()
{
$this->example = new Example();
}
}
?>
I know some difference for example using protected pharase.
But this is not enough in my opinion.
The first one, the object First will have the same properties/functions of Example class. Like:
if you instance two objects $ex1, $ex2:
on the second code, you’re creating an instance of example so you must access that variable to be able to call Example method.
one better example:
See the output: