reformed reformed - 1 year ago 74
PHP Question

Is constant name DEFAULT not allowed in PHP?

I'm getting an error when I try to define a constant named

. Why is this?

define('DEFAULT', true);
// or
class Test {
const DEFAULT = true;

This results in the following error:

Parse error: syntax error, unexpected 'DEFAULT' (T_DEFAULT) in ... on line X

Answer Source

It's not allowed, because default is a reserved word. It is used in switch blocks.

switch( $x )
    case 1: echo $x; break;
    case 2: echo $x; break;
    case 3: echo $x; break;
    default: echo $x; break;

Here is a list of the reserved words in PHP

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download