info about link
: Javascript : PHP Index : MySQL :
constant arrays
: Source : : Explanation : : Example : : Todo : : Feedback :

Why this script

PHP doesn't support the idea of an array defined as a constant. So, if you want to do this for example:
<?php
define("SOME_CONSTANT", array(1=>"one", 2=>"two"));
?>
PHP will throw an error telling you :
Warning: Constants may only evaluate to scalar values

However, it can be quite handy to have an array as a constant, since they are accessible in any scope and you have the guarantee the value will never change after defining it.

What this script can do

Basically, with this script (class) the above example is possible. Although the array you define as constant is not really a constant, it will have all the properties of a constant:
  • It is not possible to define the same array (or part of an array) twice
  • They are accessible in any scope
=[Disclaimer]=     © 2005-2012 Excudo.net