3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait AssignHandler { public function __call($name, $args) { if(preg_match("#^set([A-Z][a-zA-Z0-9_]+?)$#", $name, $matches)) { $property = strtolower($matches[1]); if(property_exists($this, $property)) { $this->{$property} = $args[0] ?? null; } } return $this; } } class Post { use AssignHandler; public $title; public $content; } $post = new Post; $post->setTitle("Value") ->setContent("example content"); print_r($post);

preferences:
34.65 ms | 408 KiB | 5 Q