note 46143 modified in function.func-get-args by danbrown

From: Date: Sat, 19 Jul 2008 21:47:47 +0000
Subject: note 46143 modified in function.func-get-args by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-141766@lists.php.net to get a copy of this message
For those who have a use for a C style enum() function: <?php //******************************************* // void enum(); // enumerates constants for unique values guarenteed. function enum() { $i=0; $ARG_ARR = func_get_args(); if (is_array($ARG_ARR)) { foreach ($ARG_ARR as $CONSTANT) { define ($CONSTANT, ++$i); } } } // USAGE: enum(ERR_USER_EXISTS, ERR_OLD_POST); // etc. etc. //******************************************* ?> this can be used for error codes etc. I deliberately skipped the 0 (zero) define, which could be useful for error checking. --was-- For those who have a use for a C style enum() function: //******************************************* // void enum(); // enumerates constants for unique values guarenteed. function enum() { $i=0; $ARG_ARR = func_get_args(); if (is_array($ARG_ARR)) { foreach ($ARG_ARR as $CONSTANT) { define ($CONSTANT, ++$i); } } } // USAGE: enum(ERR_USER_EXISTS, ERR_OLD_POST); // etc. etc. //******************************************* this can be used for error codes etc. I deliberately skipped the 0 (zero) define, which could be useful for error checking. http://php.net/manual/en/function.func-get-args.php

« previous php.notes (#141766) next »