|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29038 extract function, EXTR_PREFIX_SAME option prefixes empty strings
Submitted: 2004-07-06 22:20 UTC Modified: 2004-07-11 20:25 UTC
From: tomas_matousek at hotmail dot com Assigned:
Status: Closed Package: Arrays related
PHP Version: 5.0.0RC3 OS: WinXP
Private report: No CVE-ID: None
 [2004-07-06 22:20 UTC] tomas_matousek at hotmail dot com
The extract() function with EXTR_PREFIX_SAME option specified prefixes variable name which is an empty string, although such variable doesn't exists in the scope where extract is called.

Manual says:
If there is a collision, prefix the variable name with prefix."

And this is not true for an empty string.
A bug is possibly here (!!!):
-- array.c ----------------------------
if (!var_exists)
smart_str_appendl(&final_name, var_name, var_name_len);
/* break omitted intentionally */

if (final_name.len == 0 !!!) { ...

Reproduce code:
function f()
  extract(array("" => 1),EXTR_PREFIX_SAME,"prefix");

Expected result:

Actual result:
    [prefix_] => 1


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-07-07 00:11 UTC]
What would you have PHP do?  Create a variable with no name?
 [2004-07-07 10:43 UTC] tomas_matousek at hotmail dot com
No, skip it, like any other invalid variable name, e.g. "x y".
 [2004-07-11 20:25 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Wed Oct 04 04:01:25 2023 UTC