1

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' => 'mydb',
  'username' => 'mydb',
  'password' => 'mydbpwd',
  'prefix' => '',
  'host' => 'mydb.db.9224501.hostedresource.com',
  'port' => '3306',
  'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
  'driver' => '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->attributes->all();
$raw_parameters = $request->attributes->has('_raw_variables') ? $request->attributes->get('_raw_variables') : [];
$arguments = array();
foreach ($parameters as $param) {
  if (array_key_exists($param->name, $attributes)) {
    $arguments[] = $attributes[$param->name];
  }
  elseif (array_key_exists($param->name, $raw_parameters)) {
    $arguments[] = $attributes[$param->name];
  }
  elseif ($param->getClass() && $param->getClass()->isInstance($request)) {
    $arguments[] = $request;
  }
  elseif ($param->getClass() && $param->getClass()->name === ServerRequestInterface::class) {
    $arguments[] = $this->httpMessageFactory->createRequest($request);
  }
  elseif ($param->getClass() && ($param->getClass()->name == RouteMatchInterface::class || is_subclass_of($param->getClass()->name, RouteMatchInterface::class))) {
    $arguments[] = RouteMatch::createFromRequest($request);
  }
  elseif ($param->isDefaultValueAvailable()) {
    $arguments[] = $param->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->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.

3

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.

  • It would sure be nice if Drupal would return useful error messages instead of just crashing. – Anonymous Man Feb 9 '16 at 19:28
  • 1
    You're right it would be nice - but sadly it's not possible. Parsing happens before any code can execute, if the syntax is invalid PHP simply won't run it – Clive Feb 9 '16 at 19:51
  • 1
    Drupal does, in the installer. It wouldn't allow you to install on that environment. But when copying an existing installation, it's not really possible to detect that early enough. – Berdir Feb 9 '16 at 23:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.