PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
Copy Clear
Copy Format Clear
<?php class BaseRoProp { public function __construct( protected string $title, protected string $data ) { } } class RoProp extends BaseRoProp { public function __get(string $name) { if(property_exists($this, $name)){ return $this->$name; }else{ new \Exception('No property'); } } } $roObj = new RoProp('title 1', 'data 1'); printf('Class RoProp. Read only property Title value: %s', $roObj->title); $roBaseObj = new BaseRoProp('title 1', 'data 1'); printf('Class BaseRoProp. Read only property Title value: %s', $roBaseObj->title);
Show:  
Copy Clear