Home >Backend Development >PHP Tutorial >Why Are Abstract Static Class Methods Not Allowed in PHP 5.2 ?

Why Are Abstract Static Class Methods Not Allowed in PHP 5.2 ?

DDD
DDDOriginal
2024-11-16 07:54:03931browse

Why Are Abstract Static Class Methods Not Allowed in PHP 5.2 ?

In PHP 5.2 , Why Are Abstract Static Class Methods Not Allowed?

Originally coded without strict warnings, a project now triggers numerous warnings after enabling them. Among these is a warning about an abstract static function in the abstract parent class Program. According to documentation, abstract static functions were unintentionally allowed in PHP 5.0.x and 5.1.x and are no longer permitted.

Why Should Abstract Static Functions Not Exist?

PHP 5.2 lacked late static bindings, which became available in PHP 5.3. This feature enables parent class methods to call static methods of their child classes. Without it, abstract static methods in PHP 5.2 were ineffective since parent classes could not call child class static methods.

The Saga Continues

Upon the introduction of late static bindings, abstract static methods regained relevance. Despite this, the warning persists. While it can be argued that abstract static methods may lead to exposing broken public methods in abstract classes, this argument is considered weak.

The Curious Case of Bug Report 53081

PHP bug report 53081 requested the removal of the warning. Initially dismissed as bogus, the report was later closed as bogus due to a misunderstanding by Rasmus Lerdorf, the creator of PHP.

A Resolution in PHP 7

The warning will be removed in PHP 7 thanks to Nikita Popov's PHP RFC: Reclassify E_STRICT notices. This move towards sanity will allow developers to utilize abstract static methods without encountering the erroneous warning encountered in PHP 5.2 .

The above is the detailed content of Why Are Abstract Static Class Methods Not Allowed in PHP 5.2 ?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn