Is there a config option in PHP to prevent undefined constants from being interpreted as strings?

Posted by mrbinky3000 on Stack Overflow See other posts from Stack Overflow or by mrbinky3000
Published on 2010-05-11T16:53:49Z Indexed on 2010/05/11 17:14 UTC
Read the original article Hit count: 313

Filed under:
|
|
|
|

This is from the php manual: http://us.php.net/manual/en/language.constants.syntax.php

If you use an undefined constant, PHP assumes that you mean the name of the constant itself, just as if you called it as a string (CONSTANT vs "CONSTANT"). An error of level E_NOTICE will be issued when this happens.

I really don't like this behavior. If I have failed to define a required constant, I would rather the script fail so that I am forced define it. Is there any way to force PHP to crash the script if it tries to use an undefined constant?

For example. Both of these scripts do the same thing.

<?php
define('DEBUG',1);
if (DEBUG) echo('Yo!');
?>

and

<?php
if(DEBUG) echo('Yo!');
?>

I would rather the second script DIE and declare that it tried to use an undefined constant DEBUG.

© Stack Overflow or respective owner

Related posts about php

Related posts about define