Alex Rivera | Logout

How to initialize static variables with a function call?

Asked 2009-03-28T22:50:59.133
222

I have this code:

private static $dates = [
  'start' => mktime( 0,  0,  0,  7, 30, 2009),  // Start date
  'end'   => mktime( 0,  0,  0,  8,  2, 2009),  // End date
];

I get the following error:

Parse error: syntax error, unexpected '(', expecting ')' in /home/user/Sites/site/registration/inc/registration.class.inc on line 19

If I change mktime to a string, it works.

Anyone have any pointers?

Edit
Report

1 Answer

3

You can't make function calls in this part of the code. If you make an init() type method that gets executed before any other code does then you will be able to populate the variable then.

answered 2009-03-28T22:53:04.980

Your Answer