Laravel Spatie syntax error, unexpected token "readonly" - php

I'm getting this error anyone knows how to fix this?
It's working fine on the local server but when we set up on serverless server it throws this error.
syntax error, unexpected token "readonly" (View: /workspace/resources/views/backend/teams/form.blade.php)
in /workspace/vendor/spatie/laravel-html/src/Elements/Input.php (line 23)
use Autofocus;
use Disabled;
use MinMaxLength;
use Name;
use Placeholder;
use Readonly;
use Required;
use Type;
use Value;
use Readonly; is line 23

The issue was with PHP 8.1 as #Nigel Ren mentioned, readonly is now part of the language. I downgraded the PHP version to 7.4 and it started working.
But, if you are fine with updating the library that's the correct solution for it.

Related

Fatal error: Cannot use 'Object' as class name as it is reserved

Fatal error: Cannot use 'Object' as class name as it is reserved
I'm trying to bake my project but it shows this error.
I'm using cakephp 2.5.4 and PHP 7.0.32
I tried to change the lib folder I used the lib folder for 2.8.0
and I tried to change PHP version to 5.6.38 but nothing worked. :(
"Object" is one of the reserved keyword of PHP. You can not use it as class name. Change the class name to resolve the error.
Use Php 7.1 version. It will solve that issue
I upgraded my composer and it worked well for me.

How to use TOTP / HOTP library in PHP

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

Syntax error with session function on php5.3

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.

Error when using the "use" in php

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

Laravel 4 syntax error out-of-the-box

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.

Categories