php.net |  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
Description:
------------
---
From manual page: http://www.php.net/function.extract
---

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:
---------------
<?php
	$array = array(
		"this" => "NOT THIS" 
	);

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

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



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-04-12 04:50 UTC] requinix@php.net
-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] requinix@php.net
Creatively reassigning $this is prohibited with a fatal error as of PHP 7.1.
 [2017-04-12 04:57 UTC] requinix@php.net
...and it's not allowed anywhere: neither inside class methods nor outside. It's a very special variable.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Wed Oct 23 15:01:31 2019 UTC