3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Name { public static function split($name) { return (object) [ 'forename' => strtok($name, ' '), 'surname' => substr($name, (strpos($name, ' ') ?: -1) + 1) ]; } } echo Name::split('Daniel Michael Griffiths')->forename;

preferences:
65.4 ms | 402 KiB | 5 Q