Using static properties in PHP >= 4.3.0?

Konstantin_by

New Member
\[quote\] Disclaimer: Yes, I am forced to support PHP 4.3.0. I know it's dead. No I can't upgrade it, because I'm dealing with multiple servers some of which I don't have su access.\[/quote\]Well, since I can't use \[code\]self::\[/code\] since it's PHP5 specific, how should I go about implementing statics in a PHP4 class? So far from my research it seems that I can at least use the \[code\]static\[/code\] keyword except only in a function context, I've seen another method that uses $_GLOBALS but I don't think I'll be using that.Just so we're on the same page I need to access these PHP5 statics in 4:\[code\]public static $_monthTable = array( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);public static $_yearTable = array( 1970 => 0, 1960 => -315619200);\[/code\]So far, I've come up with my own function that basically sets a static variable if one isn't found, and I hardcode all my static properties into it. However, I'm not entirely sure how I can reference those statics within anther method in the same class, assuming it isn't being instantiated and no constructor is fired, meaning I can't use \[code\]$this\[/code\].\[code\]class DateClass { function statics( $name = null ) { static $statics = array(); if ( count( $statics ) == 0 ) { $statics['months'] = array( 'Jan', 'Feb' ); } if ( $name != null && array_key_exists($name, $statics ) ) { return $statics[$name]; } }};var_dump( DateClass::statics('months') );\[/code\]Question #1: Is this feasible? Should I try using a different method?Question #2: How would I reference the statics from a method in the same class? I tried \[code\]__CLASS__::statics\[/code\] but I think \[code\]__CLASS__\[/code\] is just a string so I'm not really invoking a method.Note: I'll be implementing this into a framework which will be used on Apache2+/IIS6+, PHP4.3.0 to PHP 5.2, OSX/Linux/Windows.
 
Back
Top