-
Notifications
You must be signed in to change notification settings - Fork 1
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
Rename methods with the same name as their class, keywords. #25
Comments
I wonder if it's ok to generate class Main {
public function __hx__main () {
}
public function __call($method, $args) {
if ($method == 'main')
return call_user_func_array([$this, '__hx__main'], $args);
} else {
//trigger error: Unknown method
}
}
} Without such magic user will get runtime error if he attempts to invoke renamed method on a dynamic var: var q : Dynamic = new Main();
q.main() //runtime error, because compiler does not know real type of `q`
//and we cannot replace `.main()" with `.__hx__main()` in compiletime
|
On the other hand dynamic access requires additonal runtime manipulations anyway. We can implement renamed fields resolution as a part of that manipulations. |
The first solution would allow the method name to be called from non-haxe code as well. But in the interest of keeping the compiled code clean, I'd go for your second suggestion. |
The third solution could be generating all code in some default namespace (which can be changed with |
That would take care of this problem. But you'll need either of the previous solutions anyway in cases where you must rename a method (for example if someone uses a php reserved keyword as method name). |
Absorbed by #47 |
* Fix for --times on OSX & linux under reporting time. * Fix for linux. * Fix for OSX without support for clock_gettime
Methods which have the same name as the class they're defined in should be renamed to prevent php from seeing them as the constructor.
I just compiled something like this:
Which results in:
This is only relevant for non-namespaced classes in the top package:
The text was updated successfully, but these errors were encountered: