php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #77135 Extract with EXTR_SKIP should skip $this
Submitted: 2018-11-10 10:27 UTC Modified: -
From: thflori at gmail dot com Assigned:
Status: Open Package: *General Issues
PHP Version: 7.2.12 OS: Manjaro
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: thflori at gmail dot com
New email:
PHP Version: OS:

 

 [2018-11-10 10:27 UTC] thflori at gmail dot com
Description:
------------
I know that get_defined_vars() is not returning $this but for every developer it feels like a variable that is currently defined inside an object context.

As you can never overwrite $this - even outside an object context it would make sense that the extract function always work as $this is defined and use the appropriate method (skip/prefix).

Test script:
---------------
<?php

$arr = ['this' => 'hello world'];
extract($arr, EXTR_SKIP);
extract($arr, EXTR_PREFIX_INVALID, 'v_');

var_dump($v_hello === $arr['this']);

Expected result:
----------------
bool(true)

Actual result:
--------------
PHP Fatal error:  Uncaught Error: Cannot re-assign $this in /tmp/test.php:4
Stack trace:
#0 /tmp/test.php(4): extract(Array, 1)
#1 {main}
  thrown in /tmp/test.php on line 4

Patches

Add a Patch

Pull Requests

Add a Pull Request

 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Mon Dec 10 08:01:24 2018 UTC