Top SEM and SEO Tips    

PHP Classes Constant Arrays

April 12, 2010 – 12:02 pm

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:

{code type=php}

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’ ,
) ;

}

{/code}

And when referencing this:

{code type=php}

AutoReport::$DelayTimes

{/code}

No related posts.

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*