Vote Up 0 Vote Down

Fatal error: Arrays are not allowed in class constants

I got the following error when I tried to declare an array in a class constant in php.

Fatal error: Arrays are not allowed in class constants

The code is as follows :

<?php 

class MyClass {

const my_array = Array (1,2,3,4);

.....


How to use an array as a class constant ?
flag

Answers


Vote Up 0 Vote Down
You can use a static variable as an alternative for using a array in a class constant:

<?php 

class MyClass {

public static $my_array = Array (1,2,3,4);

.....
flag | link |

Your Answer

Login before answering

Login with facebook