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?
Related
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
I'm getting a "syntax error, unexpected T_VARIABLE" error. I don't see what I'm doing wrong?
(4 answers)
Closed 3 years ago.
Dears,
How to concatenate a variable into array value? I Tried this way, but not works:
class Teste {
public $test=1;
public $rules2 = array('asdasd'.$test);
}
Error: Constant expression contains invalid operations
Can you help me?
Thanks!!
This question already has answers here:
Access array returned by a function in php
(5 answers)
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 3 years ago.
When I run this, it works: $content = get_content(); echo $content['content']; but when I run this echo get_content()['content']; I get Parse error: syntax error, unexpected '[', expecting ',' or ';'
Is there a way around this? I can provide the actual get_content() function if that is necessary but thought I'd start here.
Thanks!
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 6 years ago.
I'm quite new to PHP. I have created an array which I have included however when I need to echo a url which is in my settings array it just gives me the following error:
Parse error: syntax error, unexpected 'templateurl' (T_STRING) in C:\xampp\htdocs\index.php on line 15
Thanks for your help and time in advance.
Try this:
<?php include('hi.php'); echo $settings['templateurl'];?>
You need to include the file first and then you are able to retrieve the data from it.
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