rfc:static-classes
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | Next revisionBoth sides next revision | ||
rfc:static-classes [2008/05/05 20:50] – static public static!? lstrojny | rfc:static-classes [2008/05/05 20:55] – Better use case examples lstrojny | ||
---|---|---|---|
Line 9: | Line 9: | ||
Static classes are a well known construct for utility classes or stateless abstraction. C# for example has an class System.Environment to access command line options, the current directory, the name of the machine where the program is running and so on. In PHP the current practice is to use an abstract class with static methods. | Static classes are a well known construct for utility classes or stateless abstraction. C# for example has an class System.Environment to access command line options, the current directory, the name of the machine where the program is running and so on. In PHP the current practice is to use an abstract class with static methods. | ||
Static classes can act as utility containers. For such utility containers or for more complex static inheritance, | Static classes can act as utility containers. For such utility containers or for more complex static inheritance, | ||
+ | |||
Line 17: | Line 18: | ||
{ | { | ||
public static function staticMethod() | public static function staticMethod() | ||
- | {} | + | { |
+ | return ' | ||
+ | | ||
} | } | ||
abstract static class AbstractStaticClass | abstract static class AbstractStaticClass | ||
{ | { | ||
- | abstract | + | abstract public |
} | } | ||
+ | |||
+ | abstract static class AbstractStaticClass2 | ||
+ | { | ||
+ | public static function staticMethod() | ||
+ | { | ||
+ | | ||
+ | } | ||
+ | } | ||
+ | |||
+ | |||
+ | StaticClass:: | ||
+ | AbstractStaticClass2:: | ||
</ | </ | ||
rfc/static-classes.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1