Doc #74418 [Opn->Csd]: note missing from doc: extract() won't change $this
| From: | cmb@php.net | Date: | Mon, 07 Dec 2020 13:58:35 +0000 |
| Subject: | Doc #74418 [Opn->Csd]: note missing from doc: extract() won't change $this | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-18204@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=74418&edit=1
ID: 74418
Updated by: cmb@php.net
Reported by: csongor at halmai dot hu
Summary: note missing from doc: extract() won't change $this
-Status: Open
+Status: Closed
Type: Documentation Problem
Package: Arrays related
PHP Version: 7.1
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
This is not particularly related to extract(), but rather a
general property of $this, and this is already documented[1].
[1] <https://www.php.net/manual/en/language.variables.basics.php>
Previous Comments:
------------------------------------------------------------------------
[2017-04-12 04:57:00] requinix@php.net
...and it's not allowed anywhere: neither inside class methods nor outside. It's a very
special variable.
------------------------------------------------------------------------
[2017-04-12 04:50:40] requinix@php.net
Creatively reassigning $this is prohibited with a fatal error as of PHP 7.1.
------------------------------------------------------------------------
[2017-04-12 04:43:47] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=74418&edit=1