19 nov 2023 22:28:16 Lanre Waju <la...@online-presence.ca>: > 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 > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php Hi,
Super on board with this, I felt the need for this feature uncountable times in many years, usually the temporary solution was just to mark the class as final and create a private constructor, but especially the private constructor part makes it a bit ugly, too indirect and not immediately obvious. The only doubts I have about this proposal are the omission of static keywords for functions and properties. I understand this is inline with readonly classes, but I don't feel like static is a keyword that should be omittable when declaring static methods and properties. Regards, Daniil Gentili.