ID: 47409
Comment by: chrisstocktonaz at gmail dot com
Reported By: niximor at gmail dot com
Status: Open
Bug Type: Scripting Engine problem
Operating System: Windows Vista
PHP Version: 5.2.9
New Comment:
I think your second proposal on expected behavior would be more
correct, rewriting $this doesn't seem right :p Below is a simple
patch:
Index: ext/standard/array.c
===================================================================
--- ext/standard/array.c (revision 289616)
+++ ext/standard/array.c (working copy)
@@ -1364,6 +1364,10 @@
if (var_exists && var_name_len ==
sizeof("GLOBALS") && !strcmp(var_name, "GLOBALS")) {
break;
}
+ /* THIS protection */
+ if (var_exists && var_name_len ==
(sizeof("this")-1) && !strcmp(var_name, "this") && EG(scope) && "" !=
EG(scope)->name) {
+ break;
+ }
ZVAL_STRINGL(&final_name, var_name,
var_name_len, 1);
break;
Previous Comments:
------------------------------------------------------------------------
[2009-02-21 20:23:34] niximor at gmail dot com
With latest version downloaded just now (5.2.9RC4-dev) same result as
with RC2 (Test1::name = test2).
------------------------------------------------------------------------
[2009-02-16 18:48:50] niximor at gmail dot com
Description:
------------
When I use extract() with array, that contains key "this", it behaves
really weird. See code for more info.
Reproduce code:
---------------
class Test1 {
var $name = "test1";
}
class Test2 {
var $name = "test2";
function bug() {
extract(array("this"=>new Test1()), EXTR_OVERWRITE | EXTR_REFS);
echo get_class($this)."::name = ".$this->name;
}
}
$t = new Test2();
$t->bug();
Expected result:
----------------
Test1::name = test1 (preferably)
OR
Test2::name = test2
- not combination of both.
Actual result:
--------------
Test1::name = test2
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=47409&edit=1