note 69408 deleted from language.constants by googleguy

From: Date: Mon, 11 Feb 2013 05:16:17 +0000
Subject: note 69408 deleted from language.constants by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-193589@lists.php.net to get a copy of this message
Note Submitter: dexen at google dot me dot up ---- 1) Constants are invaluable when you want to be sure that *nobody* changes your important piece of data through lifetime of script -- especially when you're developing in team -- as this can cause strange, hard to track bugs. 2) Using constants is prefered over ``magic values'', as it leads to self-documenting code. Also saves you from scanning and tweaking tens of files should the value ever change. Consider example: <?php if ( $headers['code'] = 505 ) { //wth is 505? What do following code do? ?> versus: <?php if ( $headers['code'] = HTTP_VERSION_NOT_SUPPORTED ) { $this->useHttp = '1.0'; ?> In response to ``kencomer'': 3) Why not to use <?php define( 'DEBUG', FALSE ); define( 'DEBUG', TRUE ); ?> and comment one of them out as needed when developing/deploying? That'd save a lot of ugly ``if ( defined( 'DEBUG' ) && DEBUG ) {}''. 4) For debugging toggled on/off you pretty often want to use assert() anyway. You're free to turn it on/off at any moment (thou you better do it only once ;) ). assert() gives some nice details upon failed assertion, like file/line/function and context (that's invaluable!)

« previous php.notes (#193589) next »