i have the following piece of code in php:
define('QUERY', $some_query_string);
if(empty(QUERY) || mb_strlen(QUERY) < 4):
//worn the user about incorrect query input
endif;
when running this script i'm getting the fallowing error Parse error: syntax error, unexpected ')', expecting T_PAAMAYIM_NEKUDOTAYIM, but when i'm using an ordinary variable instead of constant everything works just fine!
The usage of constant is not required, but i would appreciate if anyone could explain why i'm getting that error?
(i'm newby here, so please tell me if i have to provide more details)
empty only works with variables. If you want to check whether a constant has been defined, use defined. The error messages invalid uses of empty produce aren't necessarily very intuitive, the message about T_PAAMAYIM_NEKUDOTAYIM mostly means the parser tripped up.
Related
The error that I am receiving is this: Parse error: syntax error, unexpected 'TokenType' (T_STRING) in C:\Program Files\Ampps\www\cs5339\lepichardo\4339_f22_assignment1\TokenType.php on line 2. To be clear, both files are php, and they both are in the same director. The code below is where I include the enum TokenType so that I would be able to use it.
<?php
include 'TokenType.php'
?>
The TokenType.php looks like this
<?php
enum TokenType{
case INT;
case STRING;
case COMMA;
}
?>
As far as I now, this should be fine, but gives me that error in that particular line.
If there is any other way to declare and imlpement the enum variable in php I would like to be explained to how to. Thanks in advance!!!
enums are only available in PHP 8.1+. The error suggests you are running PHP 7.
Here's some results of running the following code using various PHP versions (using https://3v4l.org/qHU4f)
<?php
enum TokenType{
case INT;
case STRING;
case COMMA;
}
echo 'hello world';
Output for 8.1.0 - 8.1.11, 8.2rc1 - rc3
hello world
Output for 8.0.1 - 8.0.24
Parse error: syntax error, unexpected identifier "TokenType" in /in/qHU4f on line 2
Process exited with code 255.
Output for 7.4.0 - 7.4.32
Parse error: syntax error, unexpected 'TokenType' (T_STRING) in /in/qHU4f on line 2
Process exited with code 255.
As you can see by the last result, unexpected 'TokenType' (T_STRING) is an error you would receive in PHP 7
I am currently trying to use the https://github.com/muesli/huephp to control my lights through PHP but I am running into a syntax problem.
Here is the line in huecli.php that I am getting a syntax error on where [...
Here is the actual error: "Parse error: syntax error, unexpected '[' "
$hue->lights()[$light]->setLight( $command );
There are more errors but it seems the [$light] is causing the problem. I haven't worked with this kind of syntax before so any help is appreciated!
You are probably not running PHP 5.4+ which is what is required to use Array Dereferencing. To use this code it must be modified as so:
$hue_lights = $hue->lights();
$hue_lights[$light]->setLight( $command );
I am having more trouble with namespacing when comes to the choice of words after this question I made earlier,
use \global\Conan as Cimmerian;
error message,
Parse error: syntax error, unexpected 'global' (T_GLOBAL), expecting
identifier (T_STRING) in C:\wamp..
So that's no way you can name a directory as global in this situation?
global is a reserved keyword in PHP, so cannot be used as an identifier.
See the List of Keywords in the PHP manual.
Although namespaces are not specifically mentioned on that page, they would cause the same problems as class names, in that the parser will not know what to do when it encounters the keyword - hence the error you are seeing.
i uploaded file but it show error.
Parse error: syntax error, unexpected '(', expecting T_STRING in ///admin.php on line 26
how can fix this error?
line is
function index($success){
include("header.php");
global $link,$prefix;
if (isset($success)) {
openTable();
echo "<center><font color='#FF0000'>$success</font><center><br>";
closeTable();
echo"<br>";
goto("index.php?file=admin");/ error line
}
Most probably you're using PHP 5.3, where goto is an operator and in that line you're calling a custom function goto(), which you've defined.
Solution: rename your function, something like go_to() will help.
Please refer PHP manual for goto here: http://php.net/manual/en/control-structures.goto.php
goto is used to shift execution to a different point in the same code file and you need to specify an identifier for another location in your code in the same file (refer to the example given in the PHP manual link). If you want to go to another link, use header() method instead.
header("Location:index.php?file=admin");
Manual here: http://php.net/manual/en/function.header.php
I've never used goto, but I just looked it up in the manual and they never used brackets around the destination. However if you want to redirect to another page, I think you're using the wrong method.
I get this PHP error:
Parse error: syntax error, unexpected
T_VARIABLE
From this line:
$list[$i][$docinfo['attrs']['#groupby']] = $docinfo['attrs']['#count'];
Is there anything wrong with this line?
There might be a semicolon or bracket missing a line before your pasted line.
It seems fine to me; every string is allowed as an array index.
It could be some other line as well. PHP is not always that exact.
Probably you are just missing a semicolon on previous line.
How to reproduce this error, put this in a file called a.php:
<?php
$a = 5
$b = 7; // Error happens here.
print $b;
?>
Run it:
eric#dev ~ $ php a.php
PHP Parse error: syntax error, unexpected T_VARIABLE in
/home/el/code/a.php on line 3
Explanation:
The PHP parser converts your program to a series of tokens. A T_VARIABLE is a Token of type VARIABLE. When the parser processes tokens, it tries to make sense of them, and throws errors if it receives a variable where none is allowed.
In the simple case above with variable $b, the parser tried to process this:
$a = 5 $b = 7;
The PHP parser looks at the $b after the 5 and says "that is unexpected".
In my case it was an issue of the PHP version.
The .phar file I was using was not compatible with PHP 5.3.9. Switching interpreter to PHP 7 did fix it.