Method overloading leads to call first defined one if number of arguments does not match #13
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Aer Information
d1b874b391
Your problem description
PH7 takes first method defined, if it does not match the arguments list.
This shows well below example, which defines 3 methods with the same name. Each of them takes different number of arguments.
Should we treat this as a bug or as a feature?
Expected results
As PH7 does not emit any errors, expected output is:
I take 0 arguments
I take 1 argument
I take 2 arguments
Current results
Actual result is:
I take 0 arguments
I take 1 argument
I take 2 arguments
I take 0 arguments
This behaviour might lead to subtle bugs I think.
In PHP this has twice behaviors because PHP does not support method overloading.
If method takes one or more arguments and we simply call a(), it ends with fatal error (too few arguments passed).
If we pass more arguments to the function than it takes, there is no error, and additional, unnecessary arguments are skipped.
I see two solutions:
We strictly match number of arguments and if there are too less, or too much of them end with error, or NOOP as method is not matched.
We copy PHP's behavior.
There is one more thing - variadic functions but I do not know if we support them? At least in 1.0?
I added variadic functions to the ideas for future releases. There are already a lot of things to do and I think we can skip this feature for now. I think P# should strictly match number of arguments for now, doesnt it?