3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait Singleton{ final public static function get_instance(...$args) { static $instance = []; $called_class = get_called_class(); if( !isset( $instance[ $called_class ] ) ) { $instance[$called_class] = new $called_class(...$args); } return $instance[ $called_class ]; } } class Database { use Singleton; protected function __construct(public readonly string $username, public readonly string $password) { } } Database::get_instance('admin', 'admin'); var_dump(Database::get_instance('readonly', 'readonly')); var_dump(Database::get_instance());
Output for git.master_jit, git.master
object(Database)#1 (2) { ["username"]=> string(5) "admin" ["password"]=> string(5) "admin" } object(Database)#1 (2) { ["username"]=> string(5) "admin" ["password"]=> string(5) "admin" }

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.35 ms | 405 KiB | 5 Q