1
2<?php
3class BaseClass {
4 function __construct() {
5 print "In BaseClass constructor\n";
6 }
7}
8
9class SubClass extends BaseClass {
10 function __construct() {
11 parent::__construct();
12 print "In SubClass constructor\n";
13 }
14}
15
16class OtherSubClass extends BaseClass {
17 // inherits BaseClass's constructor
18}
19
20// In BaseClass constructor
21$obj = new BaseClass();
22
23// In BaseClass constructor
24// In SubClass constructor
25$obj = new SubClass();
26
27// In BaseClass constructor
28$obj = new OtherSubClass();
29?>
30
31
1class Point {
2 public function __construct(
3 public float $x = 0.0,
4 public float $y = 0.0,
5 public float $z = 0.0,
6 ) {}
7}
1
2class BaseClass {
3 function __construct() {
4 print "In BaseClass constructor\n";
5 }
6}
7
8class SubClass extends BaseClass {
9 function __construct() {
10 parent::__construct();
11 print "In SubClass constructor\n";
12 }
13}
14
15