3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Box{ protected $type, $ref; function __construct($type, &$var){ $this->type = $type; $this->ref = &$var; } function __set($name, $data){ $this->ref = [$this->type, "__box"]($data); } } function §($type, &$var){ return new Box($type, $var); } // --------- class UString{ function __construct($data){ $this->data = $data; } static function __box($data){ if(is_string($data)) return new static($data); throw new Error; } } const UString = UString::CLASS; // --------- §(UString, $bar)->set = "ùnìcòdè"; var_dump($bar);

preferences:
18.74 ms | 402 KiB | 5 Q