Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Improved Zend compatibility in the reflection API. #3070

Closed
wants to merge 3 commits into from

2 participants

@whatthejeff
  • inNamespace(), getNamespaceName(), and getShortName() should not be final. This was causing issues in phpspec which mocks these methods.
  • Added missing ReflectionFunctionAbstract::getClosureScopeClass() and ReflectionFunctionAbstract::__clone().
  • Removed abstract ReflectionFunctionAbstract::getClosure() as it's not in the Zend API meaning userland classes extending ReflectionFunctionAbstract are unlikely to implement it.
  • Made ReflectionFunctionAbstract::isClosure() non-abstract as it's not abstract in the Zend API.
  • Made ReflectionFunctionAbstract::getAttributesRecursive() and ReflectionFunctionAbstract::getAttributeRecursive() non-abstract as they are missing from the Zend API and thus userland classes extending ReflectionFunctionAbstract will be missing them.
whatthejeff added some commits
@whatthejeff whatthejeff Improved Zend compatibility in the reflection API.
 * `inNamespace()`, `getNamespaceName()`, and `getShortName()` should not be
   `final`. This was causing issues in phpspec which mocks these methods.
 * Added missing `ReflectionFunctionAbstract::getClosureScopeClass()` and
   `ReflectionFunctionAbstract::__clone()`.
 * Removed abstract `ReflectionFunctionAbstract::getClosure()` as it's not in
   the Zend API meaning userland classes extending `ReflectionFunctionAbstract`
   are unlikely to implement it.
 * Made `ReflectionFunctionAbstract::isClosure()` non-abstract as it's not
   abstract in the Zend API.
0ae1d78
@whatthejeff whatthejeff Added tests for mocking `inNamespace()`, `getNamespaceName()` and `ge…
…tShortName()`.
4d0fb6c
@LiraNuna LiraNuna self-assigned this
@whatthejeff whatthejeff Improved Zend compatibility in the reflection API.
Make sure `ReflectionFunctionAbstract` can be extended by only implementing
`__toString()`.
9c1cc4f
@facebook-github-bot facebook-github-bot closed this pull request from a commit
@whatthejeff whatthejeff Improved Zend compatibility in the reflection API.
Summary: * `inNamespace()`, `getNamespaceName()`, and `getShortName()` should not be
   `final`. This was causing issues in phpspec which mocks these methods.
 * Added missing `ReflectionFunctionAbstract::getClosureScopeClass()` and
   `ReflectionFunctionAbstract::__clone()`.
 * Removed abstract `ReflectionFunctionAbstract::getClosure()` as it's not in
   the Zend API meaning userland classes extending `ReflectionFunctionAbstract`
   are unlikely to implement it.
 * Made `ReflectionFunctionAbstract::isClosure()` non-abstract as it's not
   abstract in the Zend API.

Added tests for mocking `inNamespace()`, `getNamespaceName()` and `getShortName()`.

Closes #3070

Reviewed By: @fredemmott

Differential Revision: D1411359

Pulled By: @LiraNuna
de0ac92
@whatthejeff

@LiraNuna Looks like 9c1cc4f wasn't merged. Any reason for that?

@facebook-github-bot facebook-github-bot referenced this pull request from a commit
svcscm Improved the Zend compatibility for ReflectionClass
Summary: `inNamespace()`, `getNamespaceName()`, and `getShortName()` should not be `final`. This was causing issues in phpspec which mocks these methods.

This was done for ReflectionFunctionAbstract in #3070 but ReflectionClass was missed

Closes #3233

Reviewed By: @ptarjan

Differential Revision: D1445618
8c10077
@facebook-github-bot facebook-github-bot referenced this pull request from a commit
@whatthejeff whatthejeff Improved Zend compatibility in the reflection API.
Summary: Make sure `ReflectionFunctionAbstract` can be extended by implementing only `__toString()`.

NOTE: This was part of #3070, but was accidentally left behind.
Closes #3361

Reviewed By: @LiraNuna

Differential Revision: D1478507

Pulled By: svcscm
23068f1
@MaideCa MaideCa referenced this pull request from a commit in MaideCa/hhvm
@whatthejeff whatthejeff Improved Zend compatibility in the reflection API.
Summary: Make sure `ReflectionFunctionAbstract` can be extended by implementing only `__toString()`.

NOTE: This was part of #3070, but was accidentally left behind.
Closes facebook#3361

Reviewed By: @LiraNuna

Differential Revision: D1478507

Pulled By: svcscm
2de70fb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 30, 2014
  1. @whatthejeff

    Improved Zend compatibility in the reflection API.

    whatthejeff authored
     * `inNamespace()`, `getNamespaceName()`, and `getShortName()` should not be
       `final`. This was causing issues in phpspec which mocks these methods.
     * Added missing `ReflectionFunctionAbstract::getClosureScopeClass()` and
       `ReflectionFunctionAbstract::__clone()`.
     * Removed abstract `ReflectionFunctionAbstract::getClosure()` as it's not in
       the Zend API meaning userland classes extending `ReflectionFunctionAbstract`
       are unlikely to implement it.
     * Made `ReflectionFunctionAbstract::isClosure()` non-abstract as it's not
       abstract in the Zend API.
  2. @whatthejeff
  3. @whatthejeff

    Improved Zend compatibility in the reflection API.

    whatthejeff authored
    Make sure `ReflectionFunctionAbstract` can be extended by only implementing
    `__toString()`.
This page is out of date. Refresh to see the latest.
View
10 hphp/runtime/ext/reflection/ext_reflection-classes.php
@@ -136,7 +136,7 @@ public function __toString() {
}
// Prevent cloning
- public function __clone() {
+ final public function __clone() {
throw new BadMethodCallException(
'Trying to clone an uncloneable object of class ReflectionParameter'
);
@@ -198,14 +198,14 @@ public function isPassedByReference() {
// This doc comment block generated by idl/sysdoc.php
/**
* ( excerpt from
- * http://php.net/manual/de/reflectionparameter.canbepassedbyvalue.php )
+ * http://php.net/manual/en/reflectionparameter.canbepassedbyvalue.php )
*
* Returns whether this parameter can be passed by value. Warning: This
* function is currently not documented; only its argument list is
* available.
*
* @return mixed Returns TRUE if the parameter can be passed by value,
- FALSE otherwise. Returns NULL in case of an error.
+ * FALSE otherwise. Returns NULL in case of an error.
*/
public function canBePassedByValue() {
return !isset($this->info['ref']);
@@ -573,7 +573,7 @@ public function __toString() {
}
// Prevent cloning
- public function __clone() {
+ final public function __clone() {
throw new BadMethodCallException(
'Trying to clone an uncloneable object of class ReflectionProperty'
);
@@ -907,7 +907,7 @@ public function __toString() {
}
// Prevent cloning
- public function __clone() {
+ final public function __clone() {
throw new BadMethodCallException(
'Trying to clone an uncloneable object of class ReflectionExtension'
);
View
68 hphp/runtime/ext/reflection/ext_reflection_hni.php
@@ -37,7 +37,7 @@ public function getName(): string;
*
* @return bool Returns TRUE on success or FALSE on failure.
*/
- final public function inNamespace(): bool {
+ public function inNamespace(): bool {
return strrpos($this->getName(), '\\') !== false;
}
@@ -49,7 +49,7 @@ public function getName(): string;
*
* @return string The namespace name.
*/
- final public function getNamespaceName(): string {
+ public function getNamespaceName(): string {
$name = $this->getName();
$pos = strrpos($name, '\\');
return ($pos === false) ? '' : substr($name, 0, $pos);
@@ -63,7 +63,7 @@ public function getName(): string;
*
* @return string The short name of the function.
*/
- final public function getShortName(): string {
+ public function getShortName(): string {
$name = $this->getName();
$pos = strrpos($name, '\\');
return ($pos === false) ? $name : substr($name, $pos + 1);
@@ -82,8 +82,6 @@ public function getName(): string;
<<__Native>>
public function isInternal(): bool;
- abstract public function getClosure();
-
/**
* ( excerpt from
* http://php.net/manual/en/reflectionfunctionabstract.isclosure.php )
@@ -93,7 +91,9 @@ public function isInternal(): bool;
*
* @return bool TRUE if it's a closure, otherwise FALSE
*/
- abstract public function isClosure(): bool;
+ public function isClosure(): bool {
+ return false;
+ }
/**
* ( excerpt from
@@ -238,9 +238,13 @@ public function getReturnTypeText() {
return hphp_array_idx($this->getAttributes(), $name, null);
}
- abstract public function getAttributesRecursive(): array;
+ public function getAttributesRecursive(): array {
+ return $this->getAttributes();
+ }
- abstract public function getAttributeRecursive($name);
+ public function getAttributeRecursive($name) {
+ return $this->getAttribute($name);
+ }
<<__Native>>
public function getNumberOfParameters(): int;
@@ -319,6 +323,26 @@ public function getExtensionName() {
return null;
}
+ /**
+ * ( excerpt from
+ * http://www.php.net/manual/en/reflectionfunctionabstract.getclosurescopeclass.php
+ * )
+ *
+ * Returns the scope associated to the closure
+ *
+ * @return mixed Returns the class on success or NULL on failure.
+ */
+ public function getClosureScopeClass(): ?ReflectionClass {
+ return null;
+ }
+
+ // Prevent cloning
+ final public function __clone() {
+ throw new BadMethodCallException(
+ 'Trying to clone an uncloneable object of class ' . get_class($this)
+ );
+ }
+
// Implementation of __toString
final protected function toString(
$type,
@@ -490,13 +514,6 @@ public function __toString(): string {
return $this->toString($this->isClosure() ? 'Closure' : 'Function');
}
- // Prevent cloning
- public function __clone() {
- throw new BadMethodCallException(
- 'Trying to clone an uncloneable object of class ' . get_class($this),
- );
- }
-
/**
* ( excerpt from http://php.net/manual/en/reflectionfunction.export.php )
*
@@ -600,14 +617,6 @@ public function getClosureScopeClass(): ?ReflectionClass {
}
return null;
}
-
- public function getAttributesRecursive(): array {
- return $this->getAttributes();
- }
-
- public function getAttributeRecursive($name) {
- return $this->getAttribute($name);
- }
}
/**
@@ -747,13 +756,6 @@ public function __toString(): string {
return $this->toString('Method', $preAttrs, $funcAttrs);
}
- // Prevent cloning
- public function __clone() {
- throw new BadMethodCallException(
- 'Trying to clone an uncloneable object of class ReflectionMethod'
- );
- }
-
/**
* ( excerpt from http://php.net/manual/en/reflectionmethod.export.php )
*
@@ -993,10 +995,6 @@ public function getClosure($object = null): ?Closure {
};
}
- public function isClosure(): bool {
- return false;
- }
-
/**
* ( excerpt from
* http://php.net/manual/en/reflectionmethod.setaccessible.php )
@@ -1246,7 +1244,7 @@ public function __toString(): string {
}
// Prevent cloning
- public function __clone() {
+ final public function __clone() {
throw new BadMethodCallException(
'Trying to clone an uncloneable object of class ReflectionClass'
);
View
9 hphp/test/slow/reflection/extend_reflection_function_abstract.php
@@ -0,0 +1,9 @@
+<?php
+
+class MyReflectionFunction extends ReflectionFunctionAbstract {
+ public function __toString() {
+ return "MyReflectionFunction";
+ }
+}
+
+echo new MyReflectionFunction;
View
1  hphp/test/slow/reflection/extend_reflection_function_abstract.php.expect
@@ -0,0 +1 @@
+MyReflectionFunction
View
3  hphp/test/slow/reflection/extend_reflection_method.php
@@ -2,6 +2,9 @@
class Mock_MethodReflection extends ReflectionMethod {
public function getAttributeRecursive($name) {}
+ public function inNamespace() {}
+ public function getNamespaceName() {}
+ public function getShortName() {}
}
echo "Success.\n";
Something went wrong with that request. Please try again.