symisc / PH7

An Embedded Implementation of PHP (C Library)
http://ph7.symisc.net
Other
494 stars 68 forks source link

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

Open morpheouss opened 6 years ago

morpheouss commented 6 years ago

`<?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 commented 6 years ago

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 commented 6 years ago

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.