Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Person {
- protected $id;
- protected $name;
- protected $height;
- public static $nofpeople=0;
- function __construct(){
- $this->id=rand(1000,1000000);
- print 'ID ' . $this->id . ' is assigned <br>';
- Person::$nofpeople++;
- }
- function __destruct(){
- print $this->name . ' is being destroyed<br>';
- }
- final function gender(){
- return 'n/a';
- function __get($property){
- print 'Accessed to protected property: ' . $property . '<br>';
- return $this->$property;
- }
- function __set($property, $value){
- switch($property){
- case 'name':
- $this->name = $value;
- break;
- case 'height':
- $this->height = $value;
- break;
- default:
- print $property . 'not found';
- }
- print 'Setting ' . $property . ' to ' . $value . '<br>';
- }
- }
- class employee extends person {
- function gender(){
- return 'female';
- }
- }
- $a = new employee();
- $a->name = 'Pero';
- $a->height = '1,80m';
- print $a->name . ' is ' . $a->height . ' tall.<br><br>';
- $b = new employee();
- $b->name = 'Mate';
- $b->height = '1,90m';
- if ($b instanceof Person) {
- echo $b->name . ' je osoba: bool(true)<br><br>';
- print 'Number of people created: ' . Person::$nofpeople . '<br><br>';
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement