close

[Solved] PHP Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error PHP Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP in php. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How PHP Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP Error Occurs?

Today I get the following error PHP Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP in php.

How To Solve PHP Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP Error ?

  1. How To Solve PHP Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP Error ?

    To Solve PHP Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP Error You should always use  __construct() in new code. Read php manual

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

    To Solve PHP Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP Error You should always use  __construct() in new code. Read php manual

Solution 1

You can rename your emailcomm() function with __construct():

function __construct()

instead of

function emailcomm()

or you can use the following error_reporting in your config file:

error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);

Solution 2

Solution : Rename your function name emailcomm() to __construct()

Explanation: In previous versions of PHP, if PHP cannot find a __construct() function for a given class, it will search for the old-style constructor function, by the name of the class, but now old style constructors are DEPRECATED in PHP 7.0, and will be removed in a future version. You should always use  __construct() in new code. Read php manual

   function __construct() {
      // copy your old constructor function code here
   }

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read

Leave a Comment