rfc:abstract_final_class
This is an old revision of the document!
PHP RFC: Abstract final classes
- Version: 1.0
- Date: 2014-11-26
- Author: Guilherme Blanco, guilhermeblanco@php.net
- Status: Under Discussion
- First Published at: http://wiki.php.net/rfc/abstract_final_class
Introduction
Abstract final classes are helpful in the case you are wrapping common functions that are static, but the common class itself cannot be instantiated. Currently, PHP developers' only resource is to create a final class with a private constructor, leading to untestable and error prone code.
For such, here is motivation:
- As “abstract”, it cannot be instantiated
- As “final”, it cannot be extended (such as visibility increase, behavior change, etc)
- There's no way of adding variables to a namespace. This would address this issue too
Proposal
Change language scanner to accept abstract final class constructor, and subsequently restricting to only static members.
Proposed PHP Version(s)
PHP 7
Example
abstract final class StringUtil { public static function isNotNullOrSpace($str) { return !($str === null || strlen($str) < 1 || strlen(trim($str)) < 1); } }
echo StringUtil::isNotNullOrSpace('') ? 'Empty string' : 'Non-empty string';
Proposed Voting Choices
Good question... 2/3? or 50% + 1?
Implementation
rfc/abstract_final_class.1417060830.txt.gz · Last modified: 2025/04/03 13:08 (external edit)