-
Notifications
You must be signed in to change notification settings - Fork 3k
Reflection compliance #1600
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
Reflection compliance #1600
Conversation
. For integers, check if the offset exists, raise a ReflectionException otherwise . For any other type, cast to string, search, raise a ReflectionException if not found
Fixes facebook#1572 Note: Behaves differently than PHP which fatals, using BadMethodCallException here in alignment with "fatal error: call to a method of a non-object"
Set this inside ReflectionFunctionAbstract's constructor, and call into it from both ReflectionFunction and ReflectionMethod
Compliance with PHP
PHP compliance
when there is no extension, which is the case for userland classes
…esentations PHP compliance
The name member is declared by ReflectionMethod's parent class, ReflectionFunctionAbstract, and thus appears in a different place in the output
These functions are implemented in a skeletal way and will always return NULL (or FALSE - anyways, as if there were no extension). This way, we at least no longer get fatal errors though...
Always returns FALSE at the moment This way, we at least no longer get fatal errors though
PHP Compliance
This sucks: PHP returns false instead of throwing an exception, which would be better, and we'd be able to distinguish here from the case where a class constant carries the value FALSE. Nevertheless, be compliant
Still missing: Return by reference, api doc comment, closure handling
@@ -432,6 +463,11 @@ public function isCallable() { | |||
return $this->getTypeText() === 'callable'; | |||
} | |||
|
|||
// Prevent cloning | |||
public function __clone() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not private?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To not raise fatal errors but to be able to throw an exception, in the spirit of $null->method();
also not fatalling in HHVM.
With the support of |
Fixes facebook#1499 fpi.phpCode() will already contain resolved fully qualified class names for constants such as `self::CONSTANT` or `ClassName::CONSTANT`; and will contain `CONSTANT` for global constants, both need to be evaluated in the global namespace
We now habe a __toString() implementation in ReflectionFunction Also fix up flaky tests asserting on hardcoded object ids
Indent correctly, at the same time, not like PHP (see thekid/behave@4b0850d)
See facebook#1600 (comment) This parameter is only used to detect whether too many arguments where passed and has no other meaning AFAIS
...though no. 3 surely has the least impact: -.function array_filter($arr = no_args, $func = start("""null"""), $res = start) {
+.function array_filter($arr = no_args, $func = start("""null"""), $res = start("""null""")) {
.numiters 2;
-# if we get here, a value was supplied for $res
+# if we get here, a value was supplied for $res. NULL is OK.
+ IssetL $res
+ JmpZ start
+ ...so I've implemented that for a starter. $ find hphp/test/ -name 'array_filter*.php' | grep -v bad \|
xargs ./hphp/test/run hphp/test/slow/reflection/hhas_defaults.php
Running 12 tests in 9 threads
............
All tests passed. |
$ ./hphp/test/run hphp/test/slow/reflection_classes/default_value_with_self.php
Running 1 tests in 1 threads
.
All tests passed. |
I've found a workaround to the double-namespacing issue which aligns nicely along what was done in 3504e7a to fix #1449 and #1652 but I'm not sure this is the right place |
Yes, PHP allows this, but reflection then doesn't regard these parameters as optional then, since in reality, you can't omit if from the call:) As said, it's easy to change HHVM to behave differently, but this is not this pull request's intention:) Alternatively, there's option no. 2, where we change |
I take it this will have to wait until 2.6 now? |
@GrahamCampbell yes, there was just too many issues. I'm still fighting with some and there is a chance of it going into a point release, but the prospects of 2.5 are bad. |
It's a shame. Still, it does fix a lot off issues as well as introducing some... |
@GrahamCampbell right, but more importantly it breaks things that real consumers of HHVM are using already. That can't happen. |
In that case, I'll be looking forward to 2.6 then. :) |
@ptarjan - let me know if I can do anything (or if that would make things worse:)) |
@thekid next time make lots of small PRs that can stand on their own please :) It makes bisecting errors so much easier |
You're right. This somehow escalated. |
I see that the next release will be 3.0, not 2.5. Would it be possible to delay the 3.0 release a few days so we could get this into it? |
I've been fighting through this and I think I have to declare bankruptcy. Untangling the various issues is very hard on something this large. I need you (or someone else) to split this up into multiple directed PRs that are segmented and individually tested. There are 67 commits in here, many of which are not tested and break lots of things in subtle ways. I don't know good cut points to easily test. There are lots of new functions added without any tests calling them. This is the diff I ended up with if you want to start at it and cut down instead: https://gist.github.com/10075701 |
@ptarjan all the issues referencing this one as "possible fix" should probably be reopened. |
@Ocramius which ones? The ones referenced in the top are all open except for one which was independently fixed. |
@ptarjan nvm - went through them, they are indeed all open. |
@BenMorel go for it! |
This pull request aims at achieving a greater level of compliance with the original PHP reflection API. It uses these behaviour tests to verify the Reflection classes' functionality.
These bugs are fixed:
Zend incompatibility: ReflectionParameter's function name should accept closure, not only string #1358 - Zend incompatibility: ReflectionParameter's function name should accept closure, not only string(fixed independently by aaf59cb)Furthermore, these issues are addressed:
parent
andself
as parameter type hintsThere are still differences to the PHP API which I could not or did not address here (e.g. all extension related reflection - HipHop's concept seems to work differently than PHP's, I still haven't quite understood how this could be made to work) and cases in which PHP raises errors, where HipHop throws exceptions for self-consistency.