Simple-Web3-Php icon indicating copy to clipboard operation
Simple-Web3-Php copied to clipboard

supports overloading

Open artman325 opened this issue 2 years ago • 3 comments

cann't call overloaded functions before for example we have contract code with such functions:

function foo() {
}
function foo(uint x) {
}
function foo(uint x, uint y) {
}

Actual: got error when trying to call foo() because pointing into last of list, i.e foo(uint x, uint y)

Expect: calling like this

$contract['foo()']();
$contract['foo(uint x)'](4);
$contract['foo(uint x,uint y)'](4,7);

and so on

artman325 avatar Sep 25 '23 14:09 artman325

I have mixed feelings about this one... I see the point. But it would be a really breaking change. All contract function calls would break backwards compatibility.

I'll try to think a way to store the functions by name, but keeping the arguments number to be able to call different versions.

Maybe is as simple as keeping both versions: "only function name" and "function name plus arguments". And the dev just selects whatever is their best fit.

So, your example would have exposed:

$contract['foo()']
$contract['foo(uint x)']
$contract['foo(uint x,uint y)']
$contract['foo']      //same as the 2 arguments version in your case

Best of both worlds ;)

drlecks avatar Sep 27 '23 10:09 drlecks

Okay, you can leave it as it is to maintain backward compatibility until you make it more correctly. However, developers can call overloaded functions as you do in the example example.call.php.

$res = $contract->call('foo()', []);
$res = $contract->call('foo(uint x)', [5]);
$res = $contract->call('foo(uint x,uint y)', [5,7]);

and for now, old way calls, $res = $contract->call('foo', []); pointed on foo(uint x,uint y) not on foo()

And without overloading it would works as before.
It would be more clearly

artman325 avatar Sep 27 '23 13:09 artman325