Unexpected class in ControllerResolver.php on line 151 I'm working with Drupal 8 for the first time, though fairly well experienced in 7.

I have a site working on a localhost environment just fine, and I am attempting to get it working on Go Daddy (I know they are not well regarded, but right now I need this to work.)

The entire code-tree on the localhost and server are identical. They both connect to the SAME mysql database, hosted on GoDaddy. The database is fine.

When I try to load the site from the GoDaddy host, I get the following error.


  Parse error: syntax error, unexpected 'class' (T_CLASS), expecting
  identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' in
  /home/content/01/9224501/html/mysite/drupal8/core/lib/Drupal/Core/Controller/ControllerResolver.php
  on line 151


So far, from googling the error, it seems to result from a failed database connection. I'm not sure why the same code would connect to the same database just fine from one place and not from another. 

The db connect code from settings.php is here:

$databases['default']['default'] = array (
  'database' =&gt; 'mydb',
  'username' =&gt; 'mydb',
  'password' =&gt; 'mydbpwd',
  'prefix' =&gt; '',
  'host' =&gt; 'mydb.db.9224501.hostedresource.com',
  'port' =&gt; '3306',
  'namespace' =&gt; 'Drupal\\Core\\Database\\Driver\\mysql',
  'driver' =&gt; 'mysql',
);


For what it's worth, this is the code in core that generates the error.

protected function doGetArguments(Request $request, $controller, array $parameters) {
$attributes = $request-&gt;attributes-&gt;all();
$raw_parameters = $request-&gt;attributes-&gt;has('_raw_variables') ? $request-&gt;attributes-&gt;get('_raw_variables') : [];
$arguments = array();
foreach ($parameters as $param) {
  if (array_key_exists($param-&gt;name, $attributes)) {
    $arguments[] = $attributes[$param-&gt;name];
  }
  elseif (array_key_exists($param-&gt;name, $raw_parameters)) {
    $arguments[] = $attributes[$param-&gt;name];
  }
  elseif ($param-&gt;getClass() &amp;&amp; $param-&gt;getClass()-&gt;isInstance($request)) {
    $arguments[] = $request;
  }
  elseif ($param-&gt;getClass() &amp;&amp; $param-&gt;getClass()-&gt;name === ServerRequestInterface::class) {
    $arguments[] = $this-&gt;httpMessageFactory-&gt;createRequest($request);
  }
  elseif ($param-&gt;getClass() &amp;&amp; ($param-&gt;getClass()-&gt;name == RouteMatchInterface::class || is_subclass_of($param-&gt;getClass()-&gt;name, RouteMatchInterface::class))) {
    $arguments[] = RouteMatch::createFromRequest($request);
  }
  elseif ($param-&gt;isDefaultValueAvailable()) {
    $arguments[] = $param-&gt;getDefaultValue();
  }
  else {
    if (is_array($controller)) {
      $repr = sprintf('%s::%s()', get_class($controller[0]), $controller[1]);
    }
    elseif (is_object($controller)) {
      $repr = get_class($controller);
    }
    else {
      $repr = $controller;
    }

    throw new \RuntimeException(sprintf('Controller "%s" requires that you provide a value for the "$%s" argument (because there is no default value or because there is a non optional argument after this one).', $repr, $param-&gt;name));
  }
}
return $arguments;


}

Line 151 is the 3rd elseif statement.

A similar error that I already solved was a result of GoDaddy defaulting to PHP 5.3, which was not supported by Drupal 8. I upped it to 5.4.19, which is the only other option they offer. 

My localhost is running PHP 5.5.9. I hope this is not the problem because there won't be anything I can do about it.
My localhost is running PHP 5.5.9. I hope this is not the problem because there won't be anything I can do about it.


Well there is something you can do - change your hosting provider :)

The error is indeed caused by your version of PHP - it's too old. It doesn't understand the newer method of class name resolution, introduced in 5.5. A quick search through core reveals 350+ uses, and I think there is/was an issue around somewhere to convert any uses of static strings as class names to the new way, so it's not something you could realistically work around with patches.

The PHP requirements do list 5.5.9 as a minimum version (until Drupal 8.7.0), so trying to install on anything lower than that is doomed to failure unfortunately.