Skip to content

Conversation

@artman325
Copy link

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

@drlecks
Copy link
Owner

drlecks commented Sep 27, 2023

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 ;)

@artman325
Copy link
Author

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

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

Successfully merging this pull request may close these issues.

2 participants