<?php
abstract class C {
private $s;
public function __construct($s) {
$this->s = $s;
}
//or protected function getS() {
public final function __toString() {
return $this->s;
}
}
class C1 extends C {
public function __get($name) {
$value = 'wanted:'.$name;
$this->$name = $value.',got it again';
return $value;
}
public function __construct($s1) {
parent::__construct($s1);
}
function doStuff() {
echo $this."\n";
echo $this->s."\n";
echo $this->s."\n";
}
}
$c1 = new C1('foo');
$c1->doStuff();
foo
Deprecated: Creation of dynamic property C1::$s is deprecated in /in/LQDZQ on line 17
wanted:s
wanted:s,got it again
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
foo
Deprecated: Creation of dynamic property C1::$s is deprecated in /in/LQDZQ on line 17
wanted:s
wanted:s,got it again