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);
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'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);
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 );
When the following line is reached:
$_SESSION['LOGIN'] = good_query_table($login_query)[0]["name"];
This error is printed:
PHP Parse error: syntax error, unexpected '[', expecting ',' or ';' in /srv/web/login.php on line 6
Attempting to find out what's wrong since this code has been running fine for years, I edited the code to first assign the function returned array to an array variable, then use it, which ran fine afterwards !
$arr = good_query_table( $login_quert );
$_SESSION['LOGIN'] = $arr[0]["name"];
The only new thing is that I'm now running the application on Ubuntu. It used to run for years on Windows.
So why do I have to do that ?
What version of PHP is each server running?
Function array de-referencing was added in 5.4.
http://www.php.net/manual/en/migration54.new-features.php
I'm just discovering scope resolution operators in PHP for the first time so I am trying to understand how they work. I viewed example #1 on the php.net page, and have insured I'm on PHP5.2+, however when I run the code:
<?php
class MyClass {
const CONST_VALUE = 'A constant value';
}
$classname = 'MyClass';
echo $classname::CONST_VALUE; // As of PHP 5.3.0
echo MyClass::CONST_VALUE;
?>
However, I get the following error:
Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM,
expecting ',' or ';' in
/var/www/temp/scope.php on
line 7
Didn't realise that the code only worked on PHP5.3+, I upgraded and things are working fine.