PHP - use an array as a class constant

Possible duplicate:
Is it possible to declare an array as a constant

Is it possible to use an array as a class constant in PHP ?

Ie

const MYARRAY = array('123', '234'); 

If not?

+50
arrays php const
Jun 25 2018-12-12T00:
source share
2 answers

No, you cannot assign Array to a PHP constant.

At http://www.php.net/manual/en/language.constants.syntax.php

Constants can only evaluate scalar values

That's why.

Scalar values ​​for examples: int , float , string

+61
Jun 25 2018-12-12T00:
source share

No, you can’t.

But you can 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

+65
Jun 25 '12 at 6:40
source share



All Articles