3v4l.org

run code in 300+ PHP versions simultaneously
<?php // User with a protected method class User { protected function getSomething(): string { return 'data from User'; } } // class Student that extend it class Student extends User { public function thisWorks(): void { echo 'Calling protected method from parent: ' . $this->getSomething() . "\n"; } } $s = new Student(); // Note that in this example we call a public method from "the outside" (here). $s->thisWorks(); // This does not work, because this is "global scope". // Protected methods can only be called from withing the class, as in the example above. $s->getSomething();
Output for git.master_jit, git.master
Calling protected method from parent: data from User Fatal error: Uncaught Error: Call to protected method User::getSomething() from global scope in /in/093Ao:28 Stack trace: #0 {main} thrown in /in/093Ao on line 28
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
28.56 ms | 405 KiB | 5 Q