3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class induk { protected function alas() { return "Alas"; } protected function miring() { return "Miring"; } } // turunkan class induk ke bagas class anak extends induk { protected function tinggi() { return "Tinggi"; } } // turunkan class bagas ke cucu class cucu extends bagas { protected function luas() { return "Luas"; } public function pewarisan(){ $a = $this->alas(); $b = $this->miring(); $c = $this->tinggi(); $d = $this->luas(); return "$a -> $b -> $c -> $d"; } } // buat objek dari class cucu (instansiasi) $new_pewarisan = new cucu(); //panggil method objek echo $new_pewarisan->pewarisan(); // $new_pewarisan->induk(); // Fatal error: Call to protected method komputer::induk() ?>
based on eqf7T
Output for 7.3.0alpha1 - 7.3.0rc3
Fatal error: Uncaught Error: Class 'bagas' not found in /in/MVi65:20 Stack trace: #0 {main} thrown in /in/MVi65 on line 20
Process exited with code 255.
Output for 5.6.38 - 7.2.11
Fatal error: Class 'bagas' not found in /in/MVi65 on line 20
Process exited with code 255.