3v4l.org

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

preferences:
30.56 ms | 402 KiB | 5 Q