#31974 [Com]: func_get_args() does not work when variables have "_" in the middle of the name

From: Date: Tue, 15 Feb 2005 00:42:48 +0000
Subject: #31974 [Com]: func_get_args() does not work when variables have "_" in the middle of the name
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-74084@lists.php.net to get a copy of this message
ID: 31974 Comment by: shadda at gmail dot com Reported By: pinhinha at gmail dot com Status: Open Bug Type: *Programming Data Structures Operating System: LINUX PHP Version: 5.0.3 New Comment: Got cut off. The code also works fine in my php5.0.3. Previous Comments: ------------------------------------------------------------------------ [2005-02-15 01:41:27] shadda at gmail dot com .... .... .... You do realise, array_combine() does exactly that, right? Not to mention that even were you using php4 there are several user comments throughought php.net that show you how to accomplish this very thing (And if I recall, There's a PEAR_COMPAT package that contains this functionality.) ------------------------------------------------------------------------ [2005-02-14 20:23:31] pinhinha at gmail dot com Description: ------------ Builds an associative array using value of previous defined vars. It works on PHP 4.0.10 It doens't work on PHP 5.0.3 If the var names don't have "_" (underscore) in the name it works on PHP4 AND PHP5. Reproduce code: --------------- function do_array() { $new_array=array(); foreach (func_get_args() as $var) { if (isset($GLOBALS[$var])) $new_array[$var]=$GLOBALS[$var]; else exit("<b>Error</b>: var '<b>$var</b>' is not set."); } return $new_array; } $domain_name = "php.net"; $visit_date = date("Y-m-d"); $array = do_array("domain_name", "visit_date"); Expected result: ---------------- $array = ("domain_name" => "php.net", "visit_date" => "2005-02-14" ); Actual result: -------------- Error: var 'domain_name' is not set. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=31974&edit=1

« previous php.bugs (#74084) next »