Skip to content
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

Functions / methods with same name allowed without warnings. Method attributes not considered. #24

Open
morpheouss opened this issue Jun 28, 2018 · 2 comments

Comments

@morpheouss
Copy link

`<?php
class test {

    function __construct($q) {
            echo "Constructor $q";
    }

    function a($a) {
            echo 'A';
    }

}

$x = new test('test');
$x->a();

?>`

I have created the following code snippet, and it works as expected. However I am missing any warning message about missing parameter. Since it is not optional, as there is no default value assigned to it, I believe there should be at least some information about that mistake.
What is more, if I implement additional a($a, $b) function which takes two arguments, the same code will execute the first function with matching name. I think that best solution would be that $x->a() returning NULL instead of executing some method/function that does not match parameters number.

Same happens if there are several methods with the same name / same number of parameters.
Only first declared is working and there is no information about duplicate function name.

In addition I were able to launch protected & private method from outside of class they were implemented.

@symisc
Copy link
Owner

symisc commented Jun 28, 2018

Warnings are not of particular interest in this case because PH7 support function overloading (i.e. function or methods with different parameters but same name) as an extension to the PHP programming language.

@morpheouss
Copy link
Author

I know that, but in this particular case we have 2 functions with same name (overloaded). One of them takes one argument, while second takes two arguments.

When I execute then myfunc(); I imagine that it will not match to any function with that name as there are missing parameters. There should be warning generated and code not executed at all.

Finally, if I have a class named MyClass and a private method MyMethod() inside. The following code should not work:

MyClass::MyMethod();

It should not work because it is private method.
These should be consideres as bugs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants