class A {
public $firstname;
public function __construct($firstname) {
$this->firstname = $firstname;
}
}
class B extends A {
public $lastname;
public function __construct($firstname,$lastname) {
parent::__construct($firstname);
$this->lastname= $lastname;
}
}
$class = new B('Vasya','Pupkin');
echo $class->firstname , $class->lastname;
class foo {
public function __construct() {
echo 'foo', PHP_EOL;
}
}
class bar extends foo {
public function __construct() {
echo 'bar', PHP_EOL;
}
}
$bar = new bar(); // выведет: bar
class foo {
public function __construct() {
echo 'foo', PHP_EOL;
}
}
class bar extends foo {
public function __construct() {
parent::__construct();
echo 'bar', PHP_EOL;
}
}
$bar = new bar();
//выведет:
foo
bar