Doc #74418 [Opn]: note missing from doc: extract() won't change $this

From: Date: Wed, 12 Apr 2017 04:57:00 +0000
Subject: Doc #74418 [Opn]: note missing from doc: extract() won't change $this
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-14614@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: requinix@php.net Reported by: csongor at halmai dot hu Summary: note missing from doc: extract() won't change $this Status: Open Type: Documentation Problem Package: Arrays related PHP Version: 7.1 Block user comment: N Private report: N New Comment: ...and it's not allowed anywhere: neither inside class methods nor outside. It's a very special variable. Previous Comments: ------------------------------------------------------------------------ [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

« previous php.doc.bugs (#14614) next »