PHP - use array as class constant [duplicate]
Possible Duplicate:
Is it possible to declare an array as constant
Is it possible to use an array as a class constant in PHP?
I.e
const MYARRAY = array('123', '234');
If not why?
No, you can't.
But you could declare it as a static property.
public static $MYARRAY = array('123', '234');
---------------Update-----------------------------
Array const is available from PHP 5.6.
php.net/manual/en/migration56.new-features.php
UPDATE:
This is now available in PHP 5.6 https://php.net/manual/en/migration56.new-features.php
No you can't assign an Array to PHP constant.
In http://www.php.net/manual/en/language.constants.syntax.php
Constants may only evaluate to scalar values
This is the reason.
Scalar values for examples are int
, float
, string