php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31974 func_get_args() does not work when variables have "_" in the middle of the name
Submitted: 2005-02-14 20:23 UTC Modified: 2005-02-15 01:50 UTC
From: pinhinha at gmail dot com Assigned:
Status: Not a bug Package: *Programming Data Structures
PHP Version: 5.0.3 OS: LINUX
Private report: No CVE-ID: None
 [2005-02-14 20:23 UTC] 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.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-02-15 01:41 UTC] 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-15 01:42 UTC] shadda at gmail dot com
Got cut off.

The code also works fine in my php5.0.3.
 [2005-02-15 01:42 UTC] pinhinha at gmail dot com
Miss PHP4 version, its 4.3.10
 [2005-02-15 01:50 UTC] pinhinha at gmail dot com
ZEND PROBLEM! I FORGET TO TURN IT OF! SORRY PEOPLE!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 14:01:28 2024 UTC