This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 5 months ago.
Just started learning PHP out of curiosity. Currently going through all basic fundamentals in PHP and that's when I came across this function define that we do use to define variables with constant values. However, instead of showing me an expected output, it's giving me unexpected result. Can anybody help me?
define('HOST', 'localhost'); // syntax error, unexpected identifier "define", expecting "," or ";"
define('USER', 'root');
With the limited information given in this post, i only see two point where the issue might hide.
You forgot to start your php code with a <?php start tag
You have some php code above the snippet you posted that is missing it's ;(semicolon) on the end of it's line. Good hunting :-)
Hope this helps :-)
Related
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 2 years ago.
I'm receiving the following error on my wordpress site:
An error of type E_PARSE was caused in line 56 of the file /var/www/compass.valuescentre.com/wp-content/plugins/woocommerce/woocommerce.php. Error message: syntax error, unexpected ':', expecting '{'
Below is my code from line 56-58:
function wc_get_container() : \Psr\Container\ContainerInterface { return $GLOBALS['wc_container']; }
A compiler gets problems on the exact location of a missing ),},; or ].
I would advice you to look if you missed any closing tags in the lines before 56.
if you whant to make that fast, maybe go with control + f to look for the amount of opening brakets and see if it matches the closing ones?
good luck!
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)
Closed 5 years ago.
I was running the following line on PHP5.4 without any problem:
$lstContent = $data->xpath("/response/lst[#name='highlighting']")[0]->lst[$i]->arr->str;
But now on PHP5.3 (production system) I get the following error:
Parse error: syntax error, unexpected '[' in /var/www/html/upload/inc_suche_code.php on line 153
Any ideas for a quick fix?
Updating PHP won't work for me.
In older versions of PHP you can not access array values directly on variables that are the result of a function. You have to split up the expression using a temporary variable.
$result = $data->xpath("/response/lst[#name='highlighting']");
$lstContent = $result[0]->lst[$i]->arr->str;
As of PHP 5.4 it is possible to array dereference the result of a function or method call directly. Before it was only possible using a temporary variable.
Source: http://php.net/manual/en/language.types.array.php
Edit: Obligatory "you should also consider upgrading your PHP version". This annoying limitation was fixed ages ago, not to mention that the 5.3 had its end of life in 2014, meaning it has not received security upgrades since.
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 6 years ago.
I'm using this to determine if a variable is set. I am not a beginner and normally, this works (it's not complicated either)...
if(isset($ok)) {
[stuff happening]
}
This is the return:
Parse error: syntax error, unexpected '}' in firstlaunch.php on line 6
The thing is, that's that. My file is empty but for those few lines. I'm used to fixing those types of problems but I can't see why the error is coming since that's the only PHP on my page.
Ideas?
Thanks a lot!
++++++
Edit: the full script is:
<?php
$ok = isset($_GET['flag']);
if(isset($ok)) {
}
?>
Ok guys, thanks a lot for the HEX editor suggestion, it worked: I had this thing between my { }:
 
Wonder where that came from... But now my file executes!
Thanks!
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 7 years ago.
I am trying to fopen() a debugging text file, which I have simply named debug.txt and put it on my desktop. I am using PHP. My code is simply
$debug_file = fopen( "C:\\Users\\joe\\Desktop\\debug.txt", "w" );
I keep getting this error
Parse error: syntax error, unexpected '$debug_file' (T_VARIABLE) ` on line 755, which is the line of code above.
I have checked the code before this line for a missing semicolon, as that often is the source of a syntax error, but the previous code is fine. If I comment out my one line of code, the PHP file no longer gives a syntax error.
I was thinking that there is something wrong with the way I write the string literal file path to open. I have tried to make it ok by escaping the backslashes. I'm using Windows 10. But that hasn't fixed the problem. For the life of me I can't figure out what the syntax error is.
Thanks for any help.
EDIT: As requested, the previous lines of code are:
add_shortcode('hide-it', 'hide_it_func');
function hide_it_func(){
return;
}
The problem is the line(s) above, you either didn't end it with a semicolon or there's an open bracket, or something along those lines.