5

I've got a PHP script with the following line:

$class = Connection::class;

This runs as expected on PHP 5.5 as explained here: http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.class.class. However, it causes a syntax error in PHP 5.4.

Is there a simple way that I can rewrite this line to run in PHP 5.4?

Ben Cook
  • 1,654
  • 2
  • 18
  • 32
  • _However, it causes a syntax error in PHP 5.4._ Go on, give us a clue, **what error** And a bit of code from the class definition would be useful too! – RiggsFolly Sep 11 '15 at 14:33
  • I'd imagine the error to be "unexpected T_CLASS" ... – Kevin_Kinsey Sep 11 '15 at 14:41
  • Yes, that's the error: `Parse error: syntax error, unexpected 'class' (T_CLASS), expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' in ...` – Ben Cook Sep 11 '15 at 14:46
  • 1
    Check the answer here: https://stackoverflow.com/a/34181247/1529532 – R Picheta Jun 05 '17 at 15:25

1 Answers1

2

See if this does it for you:

$class = __NAMESPACE__ ."\\".get_class($connection_object);
Kevin_Kinsey
  • 2,285
  • 1
  • 22
  • 23