php2go/fixtures/0005-inheritance.php

39 lines
481 B
PHP
Raw Normal View History

2020-04-05 06:05:32 +00:00
<?php
class Base {
protected $mX;
protected function __construct($x) {
$this->mX = $x;
}
2020-04-05 07:11:05 +00:00
public function Val(): int {
return self::TheStatic();
2020-04-05 06:23:52 +00:00
}
2020-04-05 07:11:05 +00:00
static function TheStatic(): int {
return 3;
}
2020-04-05 06:05:32 +00:00
}
class Child extends Base {
protected $mY;
public function __construct($x) {
super($x);
$this->mY = 0;
}
2020-04-05 06:23:52 +00:00
public function Val() {
return 4;
}
public function Combine() {
return $this->Val() + parent::Val();
}
2020-04-05 06:05:32 +00:00
}
2020-04-05 06:23:52 +00:00
echo (new Child(0))->Combine();