"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > Does PHP Deprecate Methods with Class Name Constructors?

Does PHP Deprecate Methods with Class Name Constructors?

Published on 2024-11-03
Browse:582

Does PHP Deprecate Methods with Class Name Constructors?

Deprecation Warning: Methods with the Same Name as Their Class

In PHP, methods with the same name as their class will no longer be constructors in future versions. This issue arises when the constructor method's name matches the class name.

Error Message:

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; TSStatus has a deprecated constructor in ... on line 10

Affected Code:

class TSStatus
{
    ...
    public function TSStatus($host, $queryPort)
    ...
}

Solution:

Replace the TSStatus method with __construct.

class TSStatus
{
    ...
    public function __construct($host, $queryPort)
    ...
}
Release Statement This article is reprinted at: 1729252215 If there is any infringement, please contact [email protected] to delete it
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3