RFC Proposal - static modifier for classes
| From: | Lanre Waju | Date: | Sun, 19 Nov 2023 21:28:08 +0000 |
| Subject: | RFC Proposal - static modifier for classes | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-121717@lists.php.net to get a copy of this message | ||
Hi, similar to the abstract and readonly modifiers to classes (similar in syntax only), I propose a class level "static" modifier that ensures:
1. The class cannot be instantiated and will throw an exception if attempted.
2. All methods and variables in the class are implicitly static.
3. (optional based on community input) It should have the same effect on traits and interfaces
For example:
static class X {
const int k = 1;
private string $a
function foo():void{}
private function bar():void{}
}
would be equivalent to
class X {
const int k = 1;
private static string $a
public static function foo():void{}
private static function bar():void{}
}
and so on. I will be implementing this myself it it gets approved.
Cheers,
Lanre