12 Apr

PHP Classes Constant Arrays

This is something I fought on Friday and got to the realization that PHP classes don’t support array constants. Not sure why not but sometimes you’re stuck with a situation and need a work around. In this instance I used static class variables in place of consts:


class AutoReport
 {

// This should be a constant but PHP constants don't handle arrays

static $DelayTimes = array( 0 => 'Run Once' ,
 60 => '1 Minute' ,
 120 => '2 Minutes' ,
 180 => '3 Minutes' ,
 240 => '4 Minutes' ,
 300 => '5 Minutes' ,
 600 => '10 Minutes' ,
 900 => '15 Minutes' ,
 1800 => '30 Minutes' ,
 3600 => '1 Hour' ,
 7200 => '2 Hours' ,
 14400 => '4 Hours' ,
 43200 => '12 Hours' ,
 ) ;

}

And when referencing this:


AutoReport::$DelayTimes

Leave a Reply

Your email address will not be published.