Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- interface Introducable {
- function introduceYourSelf();
- }
- class Person implements Introducable {
- const PI = 3.14;
- private $name;
- private $family;
- private $age;
- private static $counter = 0;
- // public readonly $size = 0;
- function __construct($name, $family, $age) {
- $this->name = $name;
- $this->family = $family;
- $this->age = $age;
- self::$counter++;
- }
- function introduceYourSelf() {
- return "My name is $this->name. I am $this->age years old!";
- }
- public static function getCounter() {
- return self::$counter;
- }
- }
- class Student extends Person {
- private $fNumber;
- function __construct($name, $family, $age, $fNumber) {
- parent::__construct($name, $family, $age);
- $this->fNumber = $fNumber;
- }
- function introduceYourSelf() {
- return parent::introduceYourSelf() . "FNumber = $this->fNumber";
- }
- }
- $stoyan = new Person("Stoyan", "Cheresharov", 54);
- $kircho = new Student("Kircho", "Ivanov", 24, "312312312");
- ?>
- <h1>Hello world!</h1>
- <pre>
- <?php
- echo $stoyan->introduceYourSelf() . PHP_EOL; // My name is Stoyan. I am 54 years old!
- echo Person::getCounter() . PHP_EOL;
- echo $stoyan::getCounter() . PHP_EOL;
- echo $stoyan->getCounter() . PHP_EOL;
- echo Person::PI . PHP_EOL;
- echo $stoyan::PI . PHP_EOL;
- echo $kircho->introduceYourSelf() . PHP_EOL; // My name is Kircho. I am 24 years old!FNumber = 312312312
- // phpinfo();
- ?>
- </pre>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement