Maximize your Laravel blog's potential with SEO best practices and reach 10K monthly clicks on Google.
Preview the course for free
Benjamin Crozat New!
Benjamin Crozat The art of crafting web applications

Methods with the same name as their class will not be constructors in a future version of PHP

Benjamin Crozat — Updated on
Artboard

Hundreds of developers subscribed to my newsletter.
Join them and enjoy free content about the art of crafting websites!

Powered by

This warning message occurs because class constructors can’t have the same name as their class. You can fix this by changing it to __construct().

Methods with the same name as their class will not be constructors in a future version of PHP
  1. Grab your favorite code editor and search for class definitions across your project;
  2. Check for constructor methods with the same name as the class and change it to __construct.

Your modifications should look like this:

class Foo
{
- public function Foo()
+ public function __construct()
{
}
}

That’s it, it’s as simple as that.

But did you know the story behind this change?

In PHP 4, as you know, a constructor was declared with the same name as its class. It was still working in PHP 5, was deprecated in PHP 7.0, and removed in PHP 8.0. That is why you must rename your constructors before migrating to version 8 or greater.

For posterity, you can read more about it on the official PHP documentation: PHP deprecated features in version 7.0.x

You can also see the PHP RFC that led to this: PHP RFC: Remove PHP 4 Constructors

Recommended

Nailing a Laravel job interview can be a daunting task, but with the right preparation and mindset, you can set yourself up for success.

PHP 8.3 will be released in November 2023, and as usual, you need to be up to date with new features and breaking changes for easier transitions.

Learning a framework can be overwhelming, but time and execution will make you a master. Here are some best practices to help you toward your goal.

Laravel 10 has been released on February 14, 2023. Let's dive into every relevant new feature and change.

I show you how to upgrade your Laravel 9 project to version 10 and help you decide whether the return on investment is worth it.

I show you how to upgrade your Laravel 8 project to version 9 and help you decide whether the return on investment is worth it.

Here's a case study for my blog in the programming niche, where I share everything I did to increase clicks by a huge amount since the beginning.

Whether PHP is dead or not is a matter of numbers, not opinions. I will provide you with essential statistics that will lead you to make better decisions.

Start leveraging the power of AI today. It enables developers to do incredible things, and many startups build products around it.

Knowing which Laravel version you are running is important before you start writing code on a new project. There are multiple ways to do so.

Powered by