note 62068 added to function.define

From: Date: Sat, 18 Feb 2006 20:12:17 +0000
Subject: note 62068 added to function.define
Groups: php.notes 
Request: Send a blank email to php-notes+get-103989@lists.php.net to get a copy of this message
benjamin, I recognise your warning, but surely a key point of constants is that their values should NOT be referenced anywhere other than their definition. richard, your solution could be made slightly safer with the use of a function for this process, e.g. <?php $iRuleVal = 0; adefine ('RULE_CALLBACK_FORMAT'); adefine ('RULE_CHANGE_CALLBACK_ON_ERROR'); adefine ('RULE_CHANGE_COMPARE_DATE'); // etc. // 'a' for auto function adefine($constant_name) { global $iRuleVal; if (defined($constant_name)) { // error handling should go here return; } // good idea to use pre-increment; avoids use of 0 // and associated equality issues with empty string // via type conversion define($constant_name, ++$iRuleVal); } ?> I think you also misnamed the original local variable - it should be $iRuleVal. ---- Server IP: 84.18.202.180 Probable Submitter: 84.92.118.11 ---- Manual Page -- http://www.php.net/manual/en/function.define.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+62068 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+62068&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+62068&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+62068&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+62068&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+62068&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+62068&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+62068&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+62068&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#103989) next »