<?php
ini_set('display_errors', true);
error_reporting(E_ALL);
abstract class papa {
public function papa() {
var_dump(__CLASS__ . '-' . __FUNCTION__);
}
}
class son extends papa {
public function son() {
var_dump(__CLASS__ . '-' . __FUNCTION__);
parent::__construct();
}
}
abstract class mama {
public function __construct() {
var_dump(__CLASS__ . '-' . __FUNCTION__);
}
public function mama() {
var_dump(__CLASS__ . '-' . __FUNCTION__);
}
}
class daughter1 extends mama {
public function daughter1() {
var_dump(__CLASS__ . '-' . __FUNCTION__);
parent::__construct();
}
}
class daughter2 extends mama {
public function daughter2() {
var_dump(__CLASS__ . '-' . __FUNCTION__);
parent::mama();
}
}
var_dump('DAUGHTER calls parent::__construct');
$girl1 = new daughter1();
var_dump('DAUGHTER calls parent::mama');
$girl2 = new daughter2();
var_dump('SON');
$boy = new son();
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; papa has a deprecated constructor in /in/pE82s on line 6
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; son has a deprecated constructor in /in/pE82s on line 12
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; daughter1 has a deprecated constructor in /in/pE82s on line 29
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; daughter2 has a deprecated constructor in /in/pE82s on line 36
string(34) "DAUGHTER calls parent::__construct"
string(19) "daughter1-daughter1"
string(16) "mama-__construct"
string(27) "DAUGHTER calls parent::mama"
string(19) "daughter2-daughter2"
string(9) "mama-mama"
string(3) "SON"
string(7) "son-son"
string(9) "papa-papa"