I have a lot of pages, all of which require
the file characters.php
. This file contains constants which define many things in my website. They are
Support for const
outside of class definitions was not added until PHP 5.3, so your 5.2.x is too old to use this. See http://php.net/const
In PHP 5.2 it's define('constant_name', 'value');
A constant must not have any $
sign at the beginning. Try const HUMAN_HEALTH = 1.1
instead.
As Marc B mentioned, const
outside classes is only available up from PHP 5.3.
To add possible causes to those already mentioned: use of the $
character, and old PHP version; I leave this clarification from the manual that was useful to detect the problem in my case:
As opposed to defining constants using define(), constants defined using the const keyword must be declared at the top-level scope because they are defined at compile-time. This means that they cannot be declared inside functions, loops, if statements or try/ catch blocks.