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
1
vote
2 answers

Fatal error: Cannot use ::class with dynamic class name in /vendor/laminas/laminas-mail/src/Message.php on line 394

I am trying to upgrade Magento 2.4.3 Adobe Cloud version to 2.4.4 and I was successfully update the composer.json with necessary changes. Also I was able to run the di:compile command successfully. Now when I am trying to access my website I am…
1
vote
1 answer

Create one to many relationship between two classes in core PHP

Kindly can someone guide me on how to achieve this? Create a class Company and define attributes Company Name, Company Address. Create a class Employees and define attributes Employee Name, Phone Number, and Email. Create a relationship …
Muhammad Yasir
  • 406
  • 3
  • 15
1
vote
1 answer

Is any change in static class scope at PHP 8.1

Today I saw a new type of code execution in PHP that was slightly different from the previous versions. The following code is executed as follows from version 8.1 onward. Anyone have an idea why?
Morteza
  • 41
  • 4
1
vote
0 answers

laravel Barryvdh dompdf error layout_line()

Im using Laravel 8, codes works perfectly before in both dev and prod server before. but when i move to PHP8, it still works in Dev server, but got an error in my production environment with this…
1
vote
1 answer

Undefined class readonly property in PhpStorm

I'm using PhpStorm 2020.3 version and error undefined class 'readonly' property in PHP 8.1 new. How to fix this error?
1
vote
0 answers

Error "Constant expression contains invalid operations" when using PHP enums in constant expressions

I have declared some values in an enum class as below, enum EmployeeGroup: int { case ADMINISTRATOR = 1; case GROUP_DEFAULT = 2; case DIRECTOR = 3; case DUH = 4; case TEAM_LEAD = 5; case SUPER_USER…
1
vote
2 answers

PHP 8.1 DOMDocument serialization

I'm trying to make the following class compatible with native PHP serialization, specifically when running on PHP 8.1. class SerializableDomDocument extends DOMDocument { private $xmlData; public function __sleep(): array { …
wazelin
  • 721
  • 11
  • 21
1
vote
1 answer

How do I count the cases in an enum and get random value or name?

How do you count the cases in an enum like this one? I have functions getRandomDataTypeName() and getRandomDataTypeValue() with for($i = 0; $i < DataType::count(); $i++) that should dynamically learn about this public static method count():int…
Toni Zeidler
  • 163
  • 1
  • 11
1
vote
0 answers

Laravel 9 and PHP 8.1.7 : Uncaught Reflection Exception: Class "config" does not exist Container.php:875

I deployed Laravel 9 on localhost and everything was good. When I deployed on cpanel shared hosting, I am getting this error. Your assistance will be appreciated. Here are some of the steps I have taken on the localhost but no difference on the…
1
vote
0 answers

Aptana studio 3.3.1 with PHP 8 syntax error

As I said I can't find where to get com.aptana.php.feature for syntax compatilility with PHP8 Can somebody help please ?
Bob
  • 21
  • 2
1
vote
1 answer

How can i use PHP 8.1 syntax in VSCODE?

I have PHP 8.1.4 installed on my PC on a C drive but I have XAMPP in drive D which have all my PHP files and I have PHP 8.1.2 in XAMPP I have PHP Intelephense installed on my VSCODE and I disable PHP Language Features but still when I write PHP 8 or…
1
vote
0 answers

Install php8.1 modules/extensions on debian11 (bullseye) php8.1 image

I've got a debian image for php, php:fpm-bullseye and it runs fine. The issue is that I want to add more php packages to this image, so according to instructions online, the steps are sudo apt update sudo apt install -y lsb-release ca-certificates…
Jake Boomgaarden
  • 3,394
  • 1
  • 17
  • 31
1
vote
1 answer

Undefined array key when insert many-to-one relation: Symfony & Doctrine

I have table cart & cart_option. Cart id (PK) cart_number total Cart_option id (PK) cart_number (FK) Here is my entity for CartOption #[ORM\ManyToOne(targetEntity: Cart::class, inversedBy: 'cartItems')] #[ORM\JoinColumn(nullable: false)] private…
nas
  • 2,289
  • 5
  • 32
  • 67
1
vote
1 answer

How to preload classes in PHP in another namespace without using the class itself?

My models are inside the namespace App\Model. With composer auto-loading, they are only loaded when in use. But I want every class/interfaces/traits inside the App\Model to be preloaded to this script file (SchemaGenerator.php which is under App…
1
vote
1 answer

Want to include just the chosen ones in the invoice

In my system for pistol competition we have an invoice system. The problem is that one can choose one or more signups but not all for creating invoices but all signups are created. For example we have two signups, John Doe and Mary Doe and I choose…
raffodog
  • 59
  • 7