Quantcast
Channel: How to initialize static variables - Stack Overflow
Viewing all articles
Browse latest Browse all 11

Answer by diggie for How to initialize static variables

$
0
0

Instead of finding a way to get static variables working, I prefer to simply create a getter function. Also helpful if you need arrays belonging to a specific class, and a lot simpler to implement.

class MyClass{   public static function getTypeList()   {       return array("type_a"=>"Type A","type_b"=>"Type B",           //... etc.       );   }}

Wherever you need the list, simply call the getter method. For example:

if (array_key_exists($type, MyClass::getTypeList()) {     // do something important...}

Viewing all articles
Browse latest Browse all 11

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>