I have a taxi system, and this code gives me
<?php
namespace App\Controllers;
use Illuminate\Http\Request;
class Controller
{
public Request $request;
public array $user;
public function __construct()
{
$this->user = [];
$this->request = Request::capture();
if (key_exists('user', $_SESSION)) {
$this->user = $_SESSION['user'];
}
if (count($this->user) === 0 && url()->contains('panel')) {
return redirect(url('login-form'));
}
}
}
but the system is giving me error after writing these lines of code
ParseError
syntax error, unexpected 'Request' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST)
Yeah, typed properties were introduced in PHP 7.4. In order to make your code snippet work, please remove properties type hints. Or update your PHP version to 7.4.
<?php
namespace App\Controllers;
use Illuminate\Http\Request;
class Controller
{
public $request;
public $user;
public function __construct()
{
$this->user = [];
$this->request = Request::capture();
if (key_exists('user', $_SESSION)) {
$this->user = $_SESSION['user'];
}
if (count($this->user) === 0 && url()->contains('panel')) {
return redirect(url('login-form'));
}
}
}
Typed properties were introduced in PHP 7.4: https://www.php.net/manual/en/migration74.new-features.php#migration74.new-features.core.typed-properties
If you are using an older PHP version, it will throw an error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With