|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #74418 note missing from doc: extract() won't change $this
Submitted: 2017-04-12 04:43 UTC Modified: 2017-04-12 04:56 UTC
From: csongor at halmai dot hu Assigned:
Status: Open Package: Arrays related
PHP Version: 7.1 OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2017-04-12 04:43 UTC] csongor at halmai dot hu
From manual page:

There is some non-documented behaviour when $array has a "this" key.  

If extract($array) is invoked within an object method then $this is not overwritten. This is totally understandable but 
- it should be documented 
- it should raise a notice

If extract() is invoked NOT within a method then $this is created. This looks logical but it contradicts the fact that $this cannot be created with a simple assignment. If this is an intended behaviour then it also should be documented, otherwise this is a bug. 

Test script:
	$array = array(
		"this" => "NOT THIS" 

	class C {
		function t($arr) {
			print "this:";
			print_r($this);  // displays the object, not "NOT THIS", as one would expect
	$c = new C();

	extract($array);  // it creates $this
	print $this;
	// $this = 0;   // this line would raise a Fatal Error


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-04-12 04:50 UTC]
-Summary: missing from doc: extract() doesn't change $this in a method +Summary: note missing from doc: extract() won't change $this -Package: Documentation problem +Package: Arrays related -PHP Version: 5.6.30 +PHP Version: 7.1
 [2017-04-12 04:50 UTC]
Creatively reassigning $this is prohibited with a fatal error as of PHP 7.1.
 [2017-04-12 04:57 UTC]
...and it's not allowed anywhere: neither inside class methods nor outside. It's a very special variable.
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed Oct 28 14:01:23 2020 UTC