Questions tagged [php-8.1]

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

PHP 8.1 (released November 2021) includes many new features including:

A full list of changes can be found in the migration guide.

336 questions
7
votes
4 answers

Check if PHP enum contains case, like try() method on basic (not backed) enumerations

I have basic enum enum Fruit { case APPLE; case ORANGE; case BANANA; } and some function that uses typing with that enum: function eatFruit (Fruit $fruit) { // do stuff } and variable with unknown content $fruit = $_POST['fruit']; // user…
norr
  • 1,725
  • 1
  • 20
  • 33
7
votes
3 answers

Passing null to non-nullable internal function parameters - Updating Existing Code Base to php 8.1

I am just getting started on upgrading my code to be php 8.1 compatible. I have many pieces of code where I am passing potentially null values to internal functions. if (strlen($row) > 0) { ... } Where $row comes from a source that may have…
mseifert
  • 5,390
  • 9
  • 38
  • 100
7
votes
3 answers

Unknown column 'wp_' in 'field list' when running WordPress on PHP 8.1

Is it possible to run Wordpress on PHP 8.1 right now? I have installed PHP 8.1 in XAMPP, but I can't get Wordpress to work. I get this error message: [23-Nov-2021 18:44:43 UTC] PHP Fatal error: Uncaught mysqli_sql_exception: Unknown column 'wp_'…
Mike C
  • 353
  • 1
  • 5
  • 12
6
votes
2 answers

Trying to install the phpize extension on the Ubuntu php8.1

I am trying to install the phpize on Ubuntu 20.04 PHP 8.1 I tried following commands but no luck sudo apt-get install php8.0-dev E: Unable to locate package php8.0-dev E: Couldn't find any package by glob 'php8.0-dev' E: Couldn't find any package…
Sivabalan
  • 971
  • 2
  • 18
  • 43
6
votes
1 answer

How do I change a readonly property using reflection in PHP 8.1?

Is there any way, using reflection or otherwise, to change a readonly property that has already been set? We sometimes do that in tests, and we don't want to avoid using readonly props just for testing purposes. class Acme { public function…
Matt Janssen
  • 1,505
  • 13
  • 14
6
votes
4 answers

Getting an PHP enum from dynamic name

I´m trying to create an php 8.1 enum from a dynamic name. Seems not to be possible. So given an enum enum Foo { case bar; } The following works of course: Foo::bar While this doesn´t: $name = "bar"; Foo::${$name} This results in: Access to…
GubGubGub
  • 61
  • 1
  • 3
6
votes
2 answers

enum class in ternary expression

Enums were introduced to PHP very recently. I'm trying them out in a laravel project. I've got my enum class here: namespace App\Enums; enum AlertType { case SUCCESS; case ERROR; } I'm trying to create an alert class that will take the…
joshua jackson
  • 629
  • 1
  • 6
  • 17
6
votes
1 answer

What is the benefit of readonly in PHP 8.1?

readonly is now available in PHP 8.1, I just wonder what is the use of it? Is that to help the editor to know that this property is just readonly or to help the client to know that or there is another benefit?
TheGeeky
  • 962
  • 1
  • 12
  • 34
5
votes
1 answer

Laminas Cache config issue after updated to PHP 8.1 from zend3

I work on a project which is recently updated to Laminas and PHP 8.1 from Zend3 and PHP 7.4. in config/autoload/global.php 'caches' => require __DIR__ . '/caches.php', and this is caches.php $cacheDefault = [ 'adapter' => [ 'name' …
5
votes
2 answers

Laravel Enum casting error Call to undefined method App\\Enums\\UserType::from()

When I try to cast a attribute from my model to one of my enums, it throws an erro: Call to undefined method App\Enums\UserType::from() I can not find anything about the required find() method. I followed the instructions here. My Enum…
Brotzka
  • 2,959
  • 4
  • 35
  • 56
5
votes
1 answer

PHP8.1 - how do I get imageavif() to work?

I recently upgraded my PHP version to 8.1-fpm and also upgraded Debian to Bullseye. I read somewhere that Bullseye comes with AVIF support but when I try to use imageavif(), I get the following error: PHP message: PHP Fatal error: Uncaught Error:…
user1413341
  • 226
  • 3
  • 17
4
votes
2 answers

pecl install pdo_sqlsrv MAKE fails on DDEV using Debian 11 - missing libltdl.la

I have a project that is using DDEV to run an instance with PHP 8.1. I needed to introduce the pdo_sqlsrv extension to the package, so I added a Dockerfile in the .ddev/web-build/ directory that installs the required packages, and copies a…
user9147574
  • 103
  • 6
4
votes
1 answer

AWS Elastic BeanStalk with PHP 8.1

Trying to upgrade elastic beanstalk to php 8.1, I need it for composer monolog and symfony. Error logs says I am on 8.0. Inside .ebextensions/02_my_commands.config I tried to add this, and I am not getting any command errors commands: …
4
votes
1 answer

PHP Date Diff Behaving Differently in PHP 8 (from 7) with Cloned Date

I have a WordPress plugin and we are upgrading our hosting from PHP 7 to 8. We have function which creates a DateTime object from a serialised date string in the session and compares it to now using the DateTime diff function. In PHP 7 this works…
Adam
  • 6,539
  • 3
  • 39
  • 65
4
votes
1 answer

PHP Readonly Properties or Constants?

Since PHP 8.1 the native support for readonly properties arrived. But we already have constants with visibilities. Please help me to answer these two questions: Which differences are between using constants and properties? When to use which one?
Phil
  • 422
  • 1
  • 5
  • 20
1
2
3
22 23