3v4l.org

run code in 300+ PHP versions simultaneously
<?php class A { protected string $city = "CityB"; private string $name = "NameA"; public function getDataA() { return [ $this->city, $this->name ]; } } class B extends A { public string $city = "CityB"; public string $name = "NameB"; public function getDataB() { return [ $this->city, $this->name ]; } } $c = new B; var_dump($c, $c->getDataA(), $c->getDataB());
Output for 8.1.0 - 8.1.32, 8.2.0 - 8.2.28, 8.3.0 - 8.3.22, 8.4.1 - 8.4.8
object(B)#1 (3) { ["city"]=> string(5) "CityB" ["name":"A":private]=> string(5) "NameA" ["name"]=> string(5) "NameB" } array(2) { [0]=> string(5) "CityB" [1]=> string(5) "NameA" } array(2) { [0]=> string(5) "CityB" [1]=> string(5) "NameB" }

preferences:
43.99 ms | 407 KiB | 5 Q