You've come across one of the many little quirks of PHP :).
Prior to PHP 5.5, empty works only on variables (more info on the manual page). This means you need to first assign $url->fragment(0) to something:
$fragment = $uri->fragment(0);
$module = empty($fragment) ? 'index' : $fragment;
Since existence isn't an issue, you don't actually need empty here (since empty($var) is equivalent to isset($var) && $var):
$module = $uri->fragment(0) ? $uri->fragment(0) : 'index';
In this situation it won't matter, but as a general piece of advice, be careful using empty with strings. It can have a few "wtf?" moments in corner cases. For example, all forms of 0 are considered empty (0, "0", 0.0).