rfc:abstract_final_class

This is an old revision of the document!


PHP RFC: IntlChar 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.1417059731.txt.gz · Last modified: 2017/09/22 13:28 (external edit)