Re: [RFC] Static classes (Was Abstract final classes)

From: Date: Mon, 01 Dec 2014 18:15:41 +0000
Subject: Re: [RFC] Static classes (Was Abstract final classes)
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-79347@lists.php.net to get a copy of this message
Am 01.12.2014 17:37 schrieb "Rowan Collins" <rowan.collins@gmail.com>: > > guilhermeblanco@gmail.com wrote on 01/12/2014 15:27: > >> (1) Function/Namespaced function autoloading >> (2) State encapsulation >> (3) Function scoping > I would add (4) static polymorphism, which Late Static Binding explicitly supports. Amen! In several places in our codebase, I make use of per-request constants by having an autoloaded baseclass file which uses class_alias for specialization, like this: // in some/class.inc class some_class__base { ... common methods and default implementation } if (class_exists('some_class_'.SOME_CONSTANT)) { class_alias('some_class', 'some_class_'.SOME_CONSTANT); } else { class_alias('some_class', 'some_class__base'); } // in some/class/special.inc class some_class_special extends some_class_base { .... specialization ... } Calling code simply uses some_class::foo() without caring whether the concrete script run then uses the specialized class, or the base class. > The only thing missing is a standardised, enforced, annotation on the class to declare that you are using this ability and instances will never be created. I that regard, I'm quite happy with private function __construct, where desired. best regards Patrick

« previous php.internals (#79347) next »