Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReflectionParameter::getDefaultValueConstantName() returns name on non-constants #3828

Closed
SiebelsTim opened this issue Sep 23, 2014 · 1 comment
Assignees

Comments

@SiebelsTim
Copy link
Contributor

define("K", 11);
function a($a = 1, $b = 'hi', $c = K) {

}

$r = new ReflectionFunction('a');

foreach($r->getParameters() as $key=>$val) {
  var_dump($val->getDefaultValueConstantName());
}

http://3v4l.org/lGLlf

Relevant for #3812

SiebelsTim referenced this issue Jan 23, 2016
Summary:
`ReflectionParameter::getDefaultValueConstantName()` was being overloaded to do
things it was not supposed to do.

http://php.net/manual/en/reflectionparameter.getdefaultvalueconstantname.php

Currently it just returns the raw text for a default value. It should only
return the text if the default value is a *constant*.

If we have:

```
define("MY_CONST", 4);
function foo($a = MY_CONST, $b = MY_CONST * MY_CONST, $c = array(MY_CONST));
```

`ReflectionParameter::getDefaultValueConstantName()` should only return a value
for `$a`. Not the others, like it is now.

So our custom `ReflectionParameter::getDefaultValueText()` should not have been deprecated.

Reviewed By: fredemmott

Differential Revision: D2831292

fb-gh-sync-id: f6a5534d74687d10f3ca9cd955f7601630fd988f
@JoelMarcey
Copy link
Contributor

Closed by: 74259b6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants