3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Thing { public function __construct( public readonly string $name, public readonly ?Thing $left = null, public readonly ?Thing $right = null, ) { } public function hasThings(): bool { return $this->left || $this->right; } public function getThingDepth(): int{ if(!$this->hasThings()) { return 1; } return max($this->left->getThingDepth(), $this->right->getThingDepth()) + 1; } public function getHtml(): string { $buf = []; $buf[] = '<table>'; $buf[] = '<tr>'; $buf[] = '<td>'; $buf[] = $this->name; $buf[] = '</td>'; if($this->hasThings()){ $buf[] = '<td>'; $buf[] = $this?->left->getHtml() ?? '-'; $buf[] = $this?->right->getHtml() ?? '-'; $buf[] = '</td>'; } $buf[] = '</tr>'; $buf[] = '</table>'; return implode("\n", $buf); } } $me = new Thing( 'Child', new Thing('Dad', new Thing('Dad\'s dad'), new Thing('Dad\'s mom')), new Thing('Mom', new Thing('Mom\'s dad'), new Thing('Mom\'s mom')), ); echo $me->getHtml();
Output for git.master_jit, git.master
<table> <tr> <td> Child </td> <td> <table> <tr> <td> Dad </td> <td> <table> <tr> <td> Dad's dad </td> </tr> </table> <table> <tr> <td> Dad's mom </td> </tr> </table> </td> </tr> </table> <table> <tr> <td> Mom </td> <td> <table> <tr> <td> Mom's dad </td> </tr> </table> <table> <tr> <td> Mom's mom </td> </tr> </table> </td> </tr> </table> </td> </tr> </table>

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:
73.37 ms | 406 KiB | 5 Q