13

We are developping a CRM.

In local, I have no problem, but in remote (OVH), I have this error message :

Parse error: syntax error, unexpected 'class' (T_CLASS), expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' in /home/dubinfo/www/CRM/model/Locataire.php on line 126

This is the code :

public function setVisites($visites) {
    $this->_visites = CheckTyper::isArrayOfModel($visites,
            VisiteMaisonInvestisseur::class, 'visites', __CLASS__);
}

The version of PHP on remote host (OVH) is 5.4.38

1
  • class is a reserved word. You shouldn't uses it as a property name.
    – Barmar
    Commented Apr 25, 2015 at 8:04

2 Answers 2

23

Using class as a name of a constant is available in PHP 5.5 only.

To get the class name you can replace VisiteMaisonInvestisseur::class with get_class(new VisiteMaisonInvestisseur).

Or change the name of the constant. For example: VisiteMaisonInvestisseur::class_name.

2
  • 1
    thank you, I changed the php version on the production server, it works... Tnank you again Commented Apr 25, 2015 at 10:04
  • 1
    Couldn't change the php version on the server, so I used get_class instead. This error disappeared, but I got others, about unexpected '(' or unexpected (T_VARIABLE) when I tried to put it inside a variable. Commented Jun 30, 2016 at 4:18
2

The problem is with VisitMaisonInvestisseur::class. class is a reserved word in PHP, so you can't use it as the name of a constant.

If it works on your local server, it must be version-specific. But I've tested this in 5.3 and 5.6, and they both report an error for Classname::class.

1
  • thank you, I changed the php version on the production server, it works... Tnank you again Commented Apr 25, 2015 at 10:04

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