Skip to content

Commit

Permalink
Remove func_num_args from Reflection
Browse files Browse the repository at this point in the history
Summary:
- Before removing func_num_args we have to remove all callsites
- This changes the way you can call these functions but just slightly.
- In the long run we should probably create getValueForStatic and setValueForStatic or something like that. And have that one enforce 1 arg and have getValue/setValue always enforce 2 args.

Reviewed By: jano

Differential Revision: D13776338

fbshipit-source-id: e204e0c92521819dab03934996ae3bb81da4b2e6
  • Loading branch information
WizKid authored and hhvm-bot committed Feb 1, 2019
1 parent 0963bd4 commit e01593d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 22 deletions.
37 changes: 20 additions & 17 deletions hphp/runtime/ext/reflection/ext_reflection-classes.php
Original file line number Diff line number Diff line change
Expand Up @@ -852,13 +852,6 @@ public function getValue($obj = null) {
$this->forceAccessible
);
}
// Can be removed once we support ParamCoerceMode in PHP
if (func_num_args() != 1) {
trigger_error('ReflectionProperty::getValue() expects exactly 1'
. ' parameter, ' . func_num_args() . ' given', E_WARNING);
return null;
}
// Can be removed once we support ParamCoerceMode in PHP
if (!is_object($obj)) {
trigger_error('ReflectionProperty::getValue() expects parameter 1'
. ' to be object, ' . gettype($obj) . ' given', E_WARNING);
Expand Down Expand Up @@ -886,17 +879,29 @@ public function getValue($obj = null) {
*
* @return mixed No value is returned.
*/
public function setValue($obj = null, $value = null) {
if (func_num_args() == 1) {
$value = $obj;
$obj = null;
}
public function setValue(mixed ...$args) {
if (!$this->isAccessible()) {
throw new ReflectionException(
"Cannot access non-public member " . $this->class .
"::" . $this->getName()
);
}

switch (count($args)) {
case 0:
$value = null;
$obj = null;
break;
case 1:
$value = $args[0];
$obj = null;
break;
default:
$value = $args[1];
$obj = $args[0];
break;
}

if ($this->isStatic()) {
hphp_set_static_property(
$this->class,
Expand All @@ -905,13 +910,11 @@ public function setValue($obj = null, $value = null) {
$this->forceAccessible
);
} else {
// Can be removed once we support ParamCoerceMode in PHP
if (func_num_args() != 2) {
trigger_error('ReflectionProperty::setValue() expects exactly 2'
. ' parameters, ' . func_num_args() . ' given', E_WARNING);
if (count($args) != 2) {
trigger_error('ReflectionProperty::setValue() expects exactly 2'.
' parameters, ' . count($args) . ' given', E_WARNING);
return null;
}
// Can be removed once we support ParamCoerceMode in PHP
if (!is_object($obj)) {
trigger_error('ReflectionProperty::setValue() expects parameter 1'
. ' to be object, ' . gettype($obj) . ' given', E_WARNING);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ int(4)
Warning: ReflectionProperty::setValue() expects parameter 1 to be object, integer given in %s/test/slow/reflection/ReflectionProperty_setValue.php on line 27
int(4)

Warning: ReflectionProperty::getValue() expects exactly 1 parameter, 0 given in %s/test/slow/reflection/ReflectionProperty_setValue.php on line 29
Warning: ReflectionProperty::getValue() expects parameter 1 to be object, NULL given in %s/test/slow/reflection/ReflectionProperty_setValue.php on line 29
NULL

Warning: ReflectionProperty::getValue() expects parameter 1 to be object, string given in %s/test/slow/reflection/ReflectionProperty_setValue.php on line 30
NULL

Warning: ReflectionProperty::getValue() expects exactly 1 parameter, 2 given in %s/test/slow/reflection/ReflectionProperty_setValue.php on line 31
NULL
Warning: ReflectionProperty::getValue() expects parameter 1 to be object, integer given in %s/test/slow/reflection/ReflectionProperty_setValue.php on line 31
NULL
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ int(4)
Warning: ReflectionProperty::setValue() expects parameter 1 to be object, integer given in %s on line %d
int(4)

Warning: ReflectionProperty::getValue() expects exactly 1 parameter, 0 given in %s on line %d
Warning: ReflectionProperty::getValue() expects parameter 1 to be object, NULL given in %s on line %d
NULL

Warning: ReflectionProperty::getValue() expects parameter 1 to be object, string given in %s on line %d
NULL

Warning: ReflectionProperty::getValue() expects exactly 1 parameter, 2 given in %s on line %d
Warning: ReflectionProperty::getValue() expects parameter 1 to be object, integer given in %s on line %d
NULL

0 comments on commit e01593d

Please sign in to comment.