The following function works on php 5.6 but gives error on php 5.3 which is the version of the cpanel im using. im unable to update the cpanel php version so i need to find a workaround..
$url =isset($_SESSION['url']) ? $_SESSION['url'] : [];
the error is:
Parse error: syntax error, unexpected '[' in /home/mydomain/public_html/mypage.php on line 7
any workaround is appreciated, thanks in advance.
Use array() instead of []. Yeah, it's PHP, not JavaScript.
Related
I tried to implement TOTP PHP library as another authentication for my login form. I downloaded and followed installation instruction from github as folowing code:
<?php
include('src/Factory.php');
include('src/HOTP.php');
include('src/HOTPInterface.php');
include('src/OTP.php');
include('src/OTPInterface.php');
include('src/ParameterTrait.php');
include('src/TOTP.php');
include('src/TOTPInterface.php');
use OTPHP\TOTP;
$otp = TOTP::create();
echo 'The current OTP is: '.$otp->now();
?>
Yet, I ended up with error message Warning: Unsupported declare 'strict_types' in C:\wamp64\www\otp\src\HOTP.php on line 3 and Parse error: syntax error, unexpected '?', expecting variable (T_VARIABLE) in C:\wamp64\www\otp\src\HOTP.php on line 28.
I could not figure out why it was that. Very much appreciate for your help. Thanks.
Install lower version of package like ~8.0, which works with PHP 5.5
https://github.com/Spomky-Labs/otphp/blob/v8.3.2/composer.json#L19
add this in your composer.json
"require": {
"spomky-labs/otphp": "~8.3"
}
Or use this link to download it as ZIP and add it to your project manually
https://github.com/Spomky-Labs/otphp/archive/v8.3.2.zip
Better is to use composer, because you have auto autoloader. :) That way there is no need to manually require files.
try the multiOTP class, which is PHP 5.x compatible
https://github.com/multiOTP/multiotp
What could be the reason this code doesn't work in PHP 5.6.23?
$change_text = [
"ok" => "Użytkownik zmieniony poprawnie.",
"new" => "Użytkownik dodany poprawnie.",
"delete" => "Użytkownik został usunięty.",
];
Works on my server with 5.6 and I've tested it on some other servers and it's fine. I moved a site to a new server and it has PHP 5.6.23 but this does't work...
Also the PHP documentation says:
As of PHP 5.4 you can also use the short array syntax, which replaces array() with [].
The error i get:
Parse error: syntax error, unexpected '[' in /...
Any ideas?
Sure the problem is old version of php. I had the same problem. I ran simple script with phpinfo() from browser and saw, that version is 5.6, but problem was in cli. So I checked version in cli, and It was 5.3! Thats it. ))
In my code, the server returns error when using the term "use". For example the following code:
use Spire\Settings;
use Spire\Resources;
use Spire\Utils;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Silex\Application;
The server returns me the following error:
PHP Parse error: syntax error, unexpected T_STRING, expecting T_CONSTANT_ENCAPSED_STRING or '(' in /home/inoshare/public_html/api/app.php on line 8
What is wrong with the server configuration?
#touchmx,Please check my below notes.
Notes :
(1) Make sure It's running PHP 5.3 or later.
(2) If they are running an earlier version they won't have support for namespaces.
Please check phpinfo() for PHP version.
I checked my php version and I see 5.2.7.
The use of syntax "use Namespace\to\class" is only available starting with version >= 5.3 of PHP.
Looks like problem solved
I am programming an app locally, but when I migrate to server I get a parse error using this line:
if(!is_array($data[array_keys($data)[0]]))
Returns:
Parse error: syntax error, unexpected '[', expecting ']' in
/home/file.php
If I rewrite the line like this:
$var1 = array_keys($data);
if(!is_array($data[$varX[0]]))
It works.
What do I need to activate on server, to get it working in the first example without error?
Thanks.
You need to be running PHP version 5.4 to use array dereferencing like that. I suspect on your server you have a lower version of PHP than on your local system.
http://php.net/manual/en/migration54.new-features.php
Under 'New features':
Function array dereferencing has been added, e.g. foo()[0].
What you're trying to do is called "array dereferencing" which only became available in PHP 5.4. So if your version of PHP is earlier than that like yours is, it won't work.
I just installed Laravel 4 (Illuminate) and as I opened the index.php file in a browser, I was met with this error:
Parse error: syntax error, unexpected 'yield' (T_YIELD), expecting identifier (T_STRING) in /www/Laravel4/vendor/illuminate/view/src/Illuminate/View/Environment.php on line 339
I have fixed the permissions for the meta folder, and installed all the dependencies through Composer. I am running PHP version 5.5.0alpha2 on OSX 10.8.2.
That's because yield became a language construct in PHP 5.5 (used in Generators) - but someone decided that it's a good idea to use this short word to name a function:
public function yield($section)
{
return isset($this->sections[$section]) ? $this->sections[$section] : '';
}
Downgrade to PHP 5.4 (after all, it's the current mainstream version, 5.5 is not even in beta yet) and it should work fine.