Questions tagged [php-8]

For questions specific to the usage and new features of PHP 8. Also, include the more generic [php] tag when using this tag.

PHP 8 is the current major version of , released on 26 November 2020. It succeeded , which was the last release of PHP 7. There is a migration guide to assist with upgrading and a complete list of changes.

New features

See a high-level overview of new features or a complete list as part of the migration guide.

Removed features

These features were deprecated in previous releases and removed in PHP 8.0

  • Old PHP 4-style constructors (methods with the same name as the class)
  • The ability to call non-static methods statically
  • The track_errors php.ini directive
  • The __autoload() magic function
  • The ability of the @ operator to silence fatal errors
  • "Leading numeric" strings (i.e. 345 == "345abc" now evaluates to false)
  • Use the salt argument to password_hash().
  • The create_function() function
  • The each() function
  • The read_exif_data() function
  • The money_format() function
  • The use of array_key_exists() with objects

A complete list of removals and other backwards-incompatible changes can be found as part of the migration guide.

593 questions
10
votes
3 answers

PHP 8: Assign "resource" as property, parameter, or return type

I am updating my project from PHP 7.0 to PHP 8.0 and I couldn't find out, if it is allowed to EXPLICITLY assign resource as the data type: of a class property, of a method/function parameter, returned by a method/function, What I know right now…
PajuranCodes
  • 303
  • 3
  • 12
  • 43
10
votes
1 answer

What are the difference between PHP 8 Match expression vs PHP 7 switch case?

PHP 8 Match expression code echo match (8.0) { '8.0' => "Oh no!", 8.0 => "This is what I expected", }; //> This is what I expected PHP 7 switch code switch (8.0) { case '8.0': $result = "Oh no!"; break; case 8.0: $result =…
8
votes
2 answers

Does eloquent support array enum casting?

Eloquent allows Enum Casting. Eloquent also allows you to cast your attribute values to PHP enums. To accomplish this, you may specify the attribute and enum you wish to cast in your model's $casts property array: use App\Enums\ServerStatus; /** …
k0pernikus
  • 60,309
  • 67
  • 216
  • 347
8
votes
1 answer

PhpStorm hint ArrayShape?

I'm defining a class as follow, using the suggestion from https://blog.jetbrains.com/phpstorm/2020/10/phpstorm-2020-3-eap-4/#arrayshape to define the array shape as a constant so that it can be used around the project:
Mrweiner
  • 481
  • 1
  • 8
  • 23
8
votes
2 answers

Unable to enable GD with JPEG support in PHP8 container running in Docker

Tried many ways, but still unable to get GD enabled with JPEG support in PHP8 container running in Docker. Here's the fragment of my Docker file: FROM php:8.0.10-apache RUN apt-get -y update && apt-get -y install \ apt-utils \ vim \ rsync \ curl…
Aidas
  • 1,213
  • 2
  • 10
  • 16
8
votes
2 answers

Facing issues while installing apcu_bc package on PHP 8

Facing below errors while installing package pecl install apcu_bc on PHP 8 In file included from /tmp/pear/temp/apcu_bc/php_apc.c:35: /usr/local/include/php/ext/apcu/apc_arginfo.h:4:3: error: #error Not supported on PHP >= 8.0 # error Not…
ShaMoh
  • 1,490
  • 3
  • 18
  • 34
8
votes
1 answer

Unable to install the JSON extension in PHP's docker image

I recently started to upgrade my projects from PHP 7.4 to 8.0, and I'm currently trying to rebuild all my Docker images to PHP 8.0 as well so both my images and my environment are coherent. Before this upgrade, I was using php:7.4, and inside my…
Jaeger
  • 1,686
  • 1
  • 30
  • 50
8
votes
3 answers

Declaration of OM\Db::query(string $statement) must be compatible with PDO::query

I just installed PHP 8 and I have this error appears? How do I fix it? Fatal error: Declaration of OM\Db::query(string $statement) must be compatible with PDO::query(string $query, ?int $fetchMode = null, mixed ...$fetchModeArgs) in…
Harry
  • 357
  • 3
  • 4
  • 13
8
votes
1 answer

How to use match expression instead of switch expression

We can use match expression instead of switch case in PHP 8. How to write match expression correctly for the following switch case? switch($statusCode) { case 200: case 300: $message = null; break; case 400: $message = 'not…
Ali_Hr
  • 4,017
  • 3
  • 27
  • 34
8
votes
2 answers

What is PHP8 JIT compiler

What is PHP8 JIT? and what are the advantages it can bring to the PHP world? What I understand is, it is used for the performance improvement.
San
  • 666
  • 7
  • 27
7
votes
1 answer

PHP 8: Enum in class?

I have a class that works on only the two types a and b. My "oldstyle" code today: class Work1 { public function do(string $type):string { if ($type!="a" && $type!="b") throw new Error("wrong type"); return "type is…
WeSee
  • 3,158
  • 2
  • 30
  • 58
7
votes
4 answers

Make PHP7 and PHP 8 live together

Make PHP7 and PHP 8 live together I've upgraded from PHP 7 to PHP 8. As it's usually the case with PHP, I still have php7.4 in /usr/bin (alongside with php8.0). But, when I run the php -v command, it answers php8.0. Since then, when trying to…
Zlotz
  • 147
  • 1
  • 2
  • 12
7
votes
2 answers

Migrate to PHP 8.0: Unbinding $this when $this is used

Step by step, I am migrating my project(s) from PHP 7.1 to PHP 8.0. In the official PHP manual, in the subchapter "Deprecated Features" of the chapter "Migrating from PHP 7.3.x to PHP 7.4.x", I tried to understand the following deprecation…
PajuranCodes
  • 303
  • 3
  • 12
  • 43
7
votes
4 answers

Problem with php-cs-fixer after upgrade php to version 8

After upgrade to php8 I have a problem with php-cs-fixer which I installed globally via composer. Right now I can not use php-cs-fixer because every time I get: PHP needs to be a minimum version of PHP 5.6.0 and maximum version of PHP 7.4.*. To…
knubbe
  • 1,132
  • 2
  • 12
  • 21
7
votes
1 answer

No working "up" method in migrate Codeigniter 3 with PHP8

I just started working with CodeIgniter 3, I understand that it is already outdated, but the task is set to work with it. And I immediately had a problem, rummaged through the Internet and did not find an answer. It seems to me that I am just…
Alex A
  • 323
  • 1
  • 8
1
2
3
39 40