I’m refreshing my PHP knowledge and have a problem I can’t solve on my own:
I have a class with two private static arrays that I want to store as values of a further (multideimensional) static class array but I always get a *unexpected T_VARIABLE* error. Here is my simplyfied sample code (just with one instead of two static arrays to fill in the following multidimensional array) that fails:
class MyClass {
private static $firstArr = array('a' => 'A', 'b' => 'B');
private static $multiArr = array('a' => self::$firstArr);
}
I really don’t understand what’s wrong here. I could easily replace the self::$firstArr with the array declaration of $firstArr itself, but I’d love to understand what I’m doing wrong here, anyway.
So any comment is welcome!
Cheers,
Roman.
You can’t do any kind of extra evaluation when declaring class properties.
Link in docs
You’re right to avoid copy/paste – This sort of ‘run-time information’ is usually done in the constructor.