PHP - use array as class constant

PhpArraysConstants

Php Problem Overview


> 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?

Php Solutions


Solution 1 - Php

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

Solution 2 - 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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMartinView Question on Stackoverflow
Solution 1 - PhpxdazzView Answer on Stackoverflow
Solution 2 - PhpAlvin WongView Answer on Stackoverflow