Bug #70344 [Opn]: extract skips valid variable names
| From: | cmb@php.net | Date: | Mon, 24 Aug 2015 15:32:46 +0000 |
| Subject: | Bug #70344 [Opn]: extract skips valid variable names | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-195482@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=70344&edit=1
ID: 70344
Updated by: cmb@php.net
Reported by: danack@php.net
Summary: extract skips valid variable names
Status: Open
Type: Bug
Package: Scripting Engine problem
Operating System: N/A
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
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>
Previous Comments:
------------------------------------------------------------------------
[2015-08-24 14:36:29] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=70344&edit=1