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
4
votes
1 answer

php 8.1 - return type deprecated in older script

Trying to update to php 8.1 and noticed this deprecated notice showing up in the error logs I'd like to take care of. [14-Feb-2022 14:48:25 UTC] PHP Deprecated: Return type of TLDExtractResult::offsetExists($offset) should either be compatible with…
user756659
  • 3,372
  • 13
  • 55
  • 110
4
votes
4 answers

Get Case from enum by string

I search for a simple solution to get the case of an enum by a string. There are BackedEnums. For example:
philsak
  • 43
  • 1
  • 3
3
votes
1 answer

Cannot modify readonly property error caused by MySQLI bind_param

Are PHP8.1 read-only properties compatible with bind_param? Here is my constructor public function __construct( private readonly ?bool $alreadyLive, //If true, the article is already live and will be updated. If false, it is a new article …
GenesisBits
  • 364
  • 2
  • 23
3
votes
1 answer

how to install zip extension in php 8.1 in Cyberpanel

In vps server Php 8.1 has no zip extension installed. anyone help me to solve the problem.
Sai Wagh
  • 31
  • 2
3
votes
0 answers

Inconsistent behaviour when using enums in where query

I'm working on a website for a simracing hotlapping competition. Participants can submit an unlimited amount of lap times for a specific round in a specific season, and admins can either approve or deny these lap times. The fastest approved lap time…
Alex
  • 778
  • 3
  • 12
  • 27
3
votes
3 answers

PHP Disable Deprecation Warnings for a Single Line

I currently have all errors enabled for my site: error_reporting(E_ALL); However, in PHP 8.1, some functions are now deprecated: PHP Notice: Function date_sunset() is deprecated in index.php on line 14 Due to current requirements, I am unable to…
Westy92
  • 19,087
  • 4
  • 72
  • 54
3
votes
1 answer

substr(): Passing null to parameter #1 ($string) of type string is deprecated ? Why PHP 8.1

I have this Code PHP in my Files function getH1() { $h1 = callDescriptor('h1'); return ucfirst(substr($h1, 0, 56)); } After Upgrade to PHP 8.1 i got this Error Messages: Deprecated substr(): Passing null to parameter #1 ($string) of…
majas
  • 31
  • 1
  • 4
3
votes
1 answer

What would prevent a PHP die() from working? On my computer die() is not working

This is on MacOS with PHP 8.1.10 installed via homebrew ... Just a blank index.php code in it with only this code ... And .. render in my…
rtconner
  • 1,221
  • 12
  • 19
3
votes
2 answers

Laravel migration: using a native PHP enum

In PHP 8.1, native support for enums were introduced. How can I use them in a Laravel Migration? My first thought would be something like this, but it does not work. // migration public function up() { Schema::create('school_days',…
gfaster
  • 157
  • 2
  • 12
3
votes
0 answers

Deserialize a null to DateTime type failed in Symfony WebTestCase

The sample codes are based on Symfony 6 and PHP 8.1. I have written a test to verify the RESTful API endpoint /posts/{id}. $client->jsonRequest('GET', $url); $getByIdResponse = $client->getResponse(); echo("json response:::" .…
Hantsy
  • 8,006
  • 7
  • 64
  • 109
3
votes
2 answers

PHP fibers and memory

PHP loads classes into memory and never frees them as far as I am aware. This can be problematic when using attributes. I am wondering whether fibers could be used. How independent is a fiber? Ultimately the question is this: if a PHP fiber loads a…
chx
  • 11,270
  • 7
  • 55
  • 129
3
votes
2 answers

PHP 8.0.12 upgrade to PHP 8.1 - multiple module errors

I've been making upgrades on my Dev workstation using XAMPP for a long time now, from the various version 7s up through 8.012. I seem to have hit a wall upgrading to 8.1. I've edited the apache config to use the new version of php. Taking the…
bluethundr
  • 1,005
  • 17
  • 68
  • 141
3
votes
1 answer

How to fetch data with PDO into class with enum property?

Since the enum feature was released in PHP8.1, I was wondering how can I fetch data from my database with PDO into an object with an ENUM property. I have the following enum: enum UserType{ case Master: 1; case Admin: 2; case Manager:…
3
votes
1 answer

PHP 8 float decimal point different than PHP 7

I upgraded some accounting scripts to PHP 8.1 however I am getting incorrect floating points. I loop a few transactions debit/credit and the balance is 0 however at the end when I try to compare to zero its not working with == 0 and === 0 After a…
3
votes
2 answers

How to use ssh2 in PHP 8.0?

I read through all the incompatibilities prior to installing php 8 updates only to find out way too late that there is no support for the ssh2 extension yet that I can find. I am hoping that I am just missing something. I have been googling for a…
Owen Parker
  • 253
  • 2
  • 12
1 2
3
22 23