php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47409 extract() problem with array containing word "this"
Submitted: 2009-02-16 18:48 UTC Modified: 2009-12-23 16:34 UTC
From: niximor at gmail dot com Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 5.2.9 OS: Windows Vista
Private report: No CVE-ID: None
 [2009-02-16 18:48 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-02-21 20:23 UTC] niximor at gmail dot com
With latest version downloaded just now (5.2.9RC4-dev) same result as with RC2 (Test1::name = test2).
 [2009-10-13 18:57 UTC] chrisstocktonaz at gmail dot com
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;
 [2009-12-23 16:33 UTC] svn@php.net
Automatic comment from SVN on behalf of iliaa
Revision: http://svn.php.net/viewvc/?view=revision&revision=292549
Log: Fixed bug #47409 (extract() problem with array containing word "this").
 [2009-12-23 16:34 UTC] iliaa@php.net
This bug has been fixed in SVN.

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.


 [2009-12-24 13:07 UTC] svn@php.net
Automatic comment from SVN on behalf of tony2001
Revision: http://svn.php.net/viewvc/?view=revision&revision=292594
Log: fix the fix for #47409
use correct comparison and add missing scope checks to trunk
 [2010-01-20 16:07 UTC] svn@php.net
Automatic comment from SVN on behalf of johannes
Revision: http://svn.php.net/viewvc/?view=revision&revision=293778
Log: Merge 292549: Fixed bug #47409 (extract() problem with array containing word
"this"). (iliaa)
 [2010-01-25 14:11 UTC] svn@php.net
Automatic comment from SVN on behalf of johannes
Revision: http://svn.php.net/viewvc/?view=revision&revision=293982
Log: merge r292594: fix the fix for #47409 (tony2001)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 03:01:29 2024 UTC