This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 7 years ago.
I'm having a problem in my script class, is giving me the error:
Parse error: syntax error, unexpected '$client' (T_VARIABLE), expecting identifier (T_STRING)
But I can't figure out what is the problem with the "client Variable".
While accessing constant class members you need to use self::, but while
accessing local variable you can use simply by variable name.
So you need to use self::client instead of $client. Because $client is constant class member.
DEMO or See More Info
Related
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 2 years ago.
after establishing the connection I'm getting this kind of error in my PHP extension file. I have also tried in otherways but I get this kind of error.
You just mis-spelled "require".
Use any of these:
require 'path/to/script.php'
require('path/to/script.php')
require_once 'path/to/script.php'
require_once('path/to/script.php')
Look for the word "reqiure" in the code and replace it with require.
You are getting this error because the PHP parser does not expect that string token at that point in the syntax.
From the documentation, this is what a T_STRING is:
identifiers, e.g. keywords like parent and self, function names, class names and more are matched. See also T_CONSTANT_ENCAPSED_STRING.
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
instantiate a class from a variable in PHP?
(5 answers)
dynamic class names in php
(7 answers)
Closed 2 years ago.
I am trying to make a small script that will load php files and then initiate classes automatically. I am trying to do it like this,
$className = ucfirst($folderName).'()';
\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new \Elementor\$className );
//HERE I AM GETTING ERROR BECAUSE OF THE $class VARIABLE USED.
The error I get:
Parse error: syntax error, unexpected '$className' (T_VARIABLE), expecting identifier (T_STRING)
How can I get ride of the error and initiate the class?
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Can you undefine or change a constant in PHP?
(6 answers)
Closed 5 years ago.
I am trying to define a session variable as constant ...
define("MY_VAR", $_SESSION['variable_name']);
I start the session before accessing this constant
However, when I try to change the value of the variable ...
MY_VAR = "xyz"
... I get following message
"Parse error: syntax error, unexpected '=' in"
I am not sure what's happening here. It would be great if someone could shed some light on this.
Note: Instead, if I use $_SESSION['variable_name'] at all places where I used MY_VAR, the code works fine
The point of constants is they are constant.
Once set you can't change them.
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 7 years ago.
namespace my;
const DHA=__NAMESPACE__."you are accessing constant"; //generate parse error
const DHA=__NAMESPACE__,"you are accessing constant"; //generate parse error
I tried concating using '.' and ',' but both it gives
Parse error: syntax error, unexpected '.', expecting ',' or ';'
EDIT (UPDATE) : This is a bug in PHP 5.5. It has been resolved in 5.6. https://wiki.php.net/rfc/const_scalar_exprs.
Which version of PHP
See https://bugs.php.net/bug.php?id=42355
Considered a new feature in 5.6
I have 5.5.9 right now and get the same results as you do
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 7 years ago.
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
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.
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.