#29038 [Opn->Csd]: extract function, EXTR_PREFIX_SAME option prefixes empty strings

From: Date: Sun, 11 Jul 2004 18:25:31 +0000
Subject: #29038 [Opn->Csd]: extract function, EXTR_PREFIX_SAME option prefixes empty strings
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-62039@lists.php.net to get a copy of this message
ID: 29038 Updated by: andrey@php.net Reported By: tomas_matousek at hotmail dot com -Status: Open +Status: Closed Bug Type: Arrays related Operating System: WinXP PHP Version: 5.0.0RC3 New Comment: 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 http://snaps.php.net/. Thank you for the report, and for helping us make PHP better. Previous Comments: ------------------------------------------------------------------------ [2004-07-07 10:43:53] tomas_matousek at hotmail dot com No, skip it, like any other invalid variable name, e.g. "x y". ------------------------------------------------------------------------ [2004-07-07 00:11:58] pollita@php.net What would you have PHP do? Create a variable with no name? ------------------------------------------------------------------------ [2004-07-06 22:20:13] tomas_matousek at hotmail dot com Description: ------------ 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: "EXTR_PREFIX_SAME 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 ---------------------------- case EXTR_PREFIX_SAME: if (!var_exists) smart_str_appendl(&final_name, var_name, var_name_len); /* break omitted intentionally */ case EXTR_PREFIX_ALL: if (final_name.len == 0 !!!) { ... break; --------------------------------------- Reproduce code: --------------- function f() { extract(array("" => 1),EXTR_PREFIX_SAME,"prefix"); print_r(get_defined_vars()); { f(); Expected result: ---------------- Array ( ) Actual result: -------------- Array ( [prefix_] => 1 ) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=29038&edit=1

« previous php.bugs (#62039) next »