Skip to content

Commit

Permalink
Fix variadic parameters always returning array on HHVM
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Jun 10, 2017
1 parent 9868a57 commit 569b3a1
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/main/php/lang/reflect/Parameter.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,17 @@ public function getType() {
!isset($details[DETAIL_ARGUMENTS][$this->_details[2]])
) {

// ReflectionParameter::getType() *always* returns "array" on HHVM, this is
// a) useless and b) inconsistent with PHP. Fall back to "var"
if (defined('HHVM_VERSION') && $this->_reflect->isVariadic()) {
return Type::$VAR;
}

// Cannot parse api doc, fall back to PHP native syntax. The reason for not doing
// this the other way around is that we have "richer" information, e.g. "string[]",
// where PHP simply knows about "arrays" (of whatever).
if ($t= $this->_reflect->getType()) {
return Type::forName((string)$t);
} else if (defined('HHVM_VERSION')) {
return Type::forName($this->_reflect->getTypeText() ?: 'var');
} else {
return Type::$VAR;
}
Expand All @@ -90,10 +94,16 @@ public function getTypeName() {
&& isset($details[DETAIL_ARGUMENTS][$this->_details[2]])
) {
return ltrim($details[DETAIL_ARGUMENTS][$this->_details[2]], '&');
} else if ($t= $this->_reflect->getType()) {
}

// ReflectionParameter::getType() *always* returns "array" on HHVM, this is
// a) useless and b) inconsistent with PHP. Fall back to "var"
if (defined('HHVM_VERSION') && $this->_reflect->isVariadic()) {
return 'var';
}

if ($t= $this->_reflect->getType()) {
return str_replace('HH\\', '', $t);
} else if (defined('HHVM_VERSION')) {
return str_replace('HH\\', '', $this->_reflect->getTypeText() ?: 'var');
} else {
return 'var';
}
Expand Down

0 comments on commit 569b3a1

Please sign in to comment.