php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70344 extract skips valid variable names
Submitted: 2015-08-24 14:36 UTC Modified: 2015-09-03 01:41 UTC
From: danack@php.net Assigned:
Status: Open Package: Scripting Engine problem
PHP Version: Irrelevant OS: N/A
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: danack@php.net
New email:
PHP Version: OS:

 

 [2015-08-24 14:36 UTC] danack@php.net
Description:
------------
The extract function skips setting variables that have names that are valid but cannot be written as a simple variable.

For example, anything with dots can be written and accessed as a variable like:

${'some.config.setting'} = 'foo';
var_dump(${'some.config.setting'});

But extract considers anything with a dot in to be an invalid variable name, and so skips doing:

extract(['some.config.setting'} => 'foo']);

fails to extract it.


Test script:
---------------
$values = [
    'value.with.dot' => 'set from array',
];

extract($values);

if (!isset(${'value.with.dot'})) {
    echo "It's not set\n";
}
else {
    var_dump(${'value.with.dot'});
}

${'value.with.dot'} = "It is a valid variable name, just not one that can be written as a non-interpolated variable.";
var_dump(${'value.with.dot'});


Expected result:
----------------
string(14) "set from array"

Actual result:
--------------
It's not set

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-08-24 15:32 UTC] cmb@php.net
FWIW, the PHP manual defines[1]:

| Variable names follow the same rules as other labels in PHP. A
| valid variable name starts with a letter or underscore, followed
| by any number of letters, numbers, or underscores. As a regular
| expression, it would be expressed thus:
| '[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*'

[1] <http://php.net/manual/en/language.variables.basics.php>
 [2015-09-03 01:41 UTC] yohgaki@php.net
We may add warning or notice for invalid key(var name).
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 17:01:58 2024 UTC