System Architecture (eg. arm, x86_64, ...): x86_64
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.
<?php
class Test {
function a() {
echo 'I take 0 arguments' . PHP_EOL;
}
function a($a) {
echo 'I take 1 argument' . PHP_EOL;
}
function a($a, $b) {
echo 'I take 2 arguments' . PHP_EOL;
}
};
$t = new Test();
$t->a();
$t->a(1);
$t->a(1, 2);
$t->a(1, 2, 3);
?>
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
<!--
1. Please speak English, this is the language all of us can speak and write.
2. Please take a moment to check that your issue doesn't already exist.
3. Please give all relevant information below for bug reports, because
incomplete details will be handled as an invalid report.
-->
# Aer Information
- Aer Version (or commit ref): d1b874b391
- Operating System: Linux
- System Architecture (eg. arm, x86_64, ...): x86_64
# 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.
<?php
class Test {
function a() {
echo 'I take 0 arguments' . PHP_EOL;
}
function a($a) {
echo 'I take 1 argument' . PHP_EOL;
}
function a($a, $b) {
echo 'I take 2 arguments' . PHP_EOL;
}
};
$t = new Test();
$t->a();
$t->a(1);
$t->a(1, 2);
$t->a(1, 2, 3);
?>
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
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?
In PHP this has twice behaviors because PHP does not support method overloading.
1. If method takes one or more arguments and we simply call a(), it ends with fatal error (too few arguments passed).
2. 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:
1. 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.
2. 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?
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?
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?