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 );
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
This function working properly with the newer PHP versions:
function MKDSLD($mkD,&$slD=array()){}
BUT
I'm getting :
Parse error: syntax error, unexpected '=', expecting ')'
With PHP 4.
Needless to say that I got to solve it under the older version of PHP :)
Pretty simple but I guess small tweak is needed here :D
Thank you in advance !
PHP 4 doesn't support default parameters for reference parameters.
You should deal with $slD as a required argument:
function MKDSLD($mkD, &$slD){
// code
}
$x = array();
MKDSLD(5, $x);
I'm having some errors with my file. Does anyone know what I did wrong?
Error:
syntax error, unexpected ':', expecting ')' in C:\wamp65\www\Php2\01_gallery.php on line 5
It gives above error when I load the page and the error comes from this line:
$arrayImages=glob( pattern: $path."/*.{".$extentions."}", flags: GLOB_BRACE);
The problem is that you are using the PHP 8 syntax but you are trying to execute this code with PHP 7. This syntax is invalid before PHP 8, so you need to make sure that you are using PHP 8.
Named arguments were introduced in PHP 8 and they allow you to provide arguments out of order because each argument is named e.g. pattern: $thisIsMyPattern.
If you can't use PHP 8 for the moment for some reason then a workaround is to remove the parameter names, which you don't even need in this example.
$arrayImages = glob($path."/*.{".$extentions."}", GLOB_BRACE);
This question already has an answer here:
Difference in accessing arrays in PHP 5.3 and 5.4 or some configuration mismatch?
(1 answer)
Closed 7 years ago.
I got few lines producing error 500. The error log says:
PHP Parse error: syntax error, unexpected '[' in...
and the lines are:
$catids[] = $params->get('catid');
and after commenting it out, this one comes up:
$return_category[] = self::_getCategoryInfor($tg, $params)[0];
How can i modify them in order to match with new PHP versions and solve the error 500?
From your code, I do not see code that may triggered this parse error. Try change your code so it becomes:
$categories = self::_getCategoryInfor($tg, $params);
$return_category[] = $categories[0];
This is the expression causing the error:
self::_getCategoryInfor($tg, $params)[0];
Function array dereferencing was added in PHP 5.4. Your code will generate a parse error on 5.3 or lower:
https://secure.php.net/manual/en/migration54.new-features.php
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.