php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #71250 ReflectionFunction getStaticVariables returns the variables defined in "use"
Submitted: 2015-12-30 21:10 UTC Modified: 2021-07-09 14:18 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: mfaust at usinternet dot com Assigned:
Status: Verified Package: Reflection related
PHP Version: 5.6.16 OS: Linux
Private report: No CVE-ID: None
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
22 - 6 = ?
Subscribe to this entry?

 
 [2015-12-30 21:10 UTC] mfaust at usinternet dot com
Description:
------------
ReflectionFunction::getStaticVariables returns the variables defined in a "use" clause of an anonymous function even though they are not specifically declared as "static" within the function.  This might be an internal implementation detail of how "use" works but they should not be reported as "static" variables in terms of reflection.

Test script:
---------------
$var = 6;
$a = function() use ($var){
   echo $var;
};

$reflected = new \ReflectionFunction($a);
var_export($reflected->getStaticVariables());

Expected result:
----------------
Should not have 'var' listed as a static variable.

array( )

Actual result:
--------------
Has 'var' listed as a static variable

array('var' => 6)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-01-02 07:36 UTC] laruence@php.net
-Assigned To: +Assigned To: laruence
 [2016-01-02 07:36 UTC] laruence@php.net
There is no such info in run-time.  thus I don't see a easy way to fix it, but maybe we could fix this in 7.1.
 [2021-07-09 14:18 UTC] cmb@php.net
-Status: Assigned +Status: Verified -Type: Bug +Type: Documentation Problem -Assigned To: laruence +Assigned To:
 [2021-07-09 14:18 UTC] cmb@php.net
See <https://3v4l.org/lUemN>.

While this *might* have been overlooked when anonymous functions
have been implemented, at this point there is likely code relying
on this behavior, so changing it would constitute a BC break.
Thus, I'm changing to documentation problem.

If anyone is interested in changing the current behavior, please
pursue the RFC process[1].

[1] <https://wiki.php.net/rfc/howto>
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun May 11 15:01:27 2025 UTC