Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is constant name DEFAULT not allowed in PHP?

Tags:

php

constants

I'm getting an error when I try to define a constant named DEFAULT. Why is this?

<?php
define('DEFAULT', true);
var_dump(DEFAULT);
// or
class Test {
    const DEFAULT = true;
}
var_dump(Test::DEFAULT);

This results in the following error:

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

like image 806
reformed Avatar asked Dec 02 '22 14:12

reformed


1 Answers

default is a reserved language keyword in PHP. It is used for the default option in a switch block.

So no, you can't use it in a define statement.

like image 136
Spudley Avatar answered Dec 23 '22 13:12

Spudley