3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Pet { public $name; public function __construct ( $name ) { $this->name = $name; } public function speak ($what) { return $what; } } class Dog extends Pet { // Le he metido el null para que el parametro sea opcional public function speak ( $what ) { return $what ? parent::speak($what) : 'Woof Woof!'; /* // Otra alternativa para meter codigo mas complicado seria: if($what) return parent::speak($what); return 'Woof Woof'; */ } public function plays() { return 'fetch'; } } $charlie = new Dog ( 'Charlie' ); echo 'The dog\'s name is ' . $charlie->name . PHP_EOL; echo 'Speak of the super class: ' . $charlie->speak('hello, my name is ' . $charlie->name) . PHP_EOL; echo 'Speak of the dog class: ' . $charlie->speak() . PHP_EOL;
Output for git.master, git.master_jit, rfc.property-hooks
The dog's name is Charlie Speak of the super class: hello, my name is Charlie Fatal error: Uncaught ArgumentCountError: Too few arguments to function Dog::speak(), 0 passed in /in/hT55g on line 47 and exactly 1 expected in /in/hT55g:23 Stack trace: #0 /in/hT55g(47): Dog->speak() #1 {main} thrown in /in/hT55g on line 23
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:
44.9 ms | 401 KiB | 8 Q