reformed reformed - 13 days ago 4x
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


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