A feature I'd quite like to see is something similar to C# out arguments.
Which is an argument provided empty to a function (or with a value to be
ignored) that the function must write to before returning.
Normally this wouldn't be necessary since you can do this anyway by passing
by reference, however I would like to make the same case for it that was
made for return types.
A possible syntax to differ from C# might be:
function read(string ^$bytes, int length): int
{
}
The arrow indicating that a value will be written to the argument.
Another case for this is the fact it is unfeasible to provide a type hint
for reference arguments because if the provided var is null or newly
created it will throw an error.
Using type hints on outputs will both validate that the populating value is
of the correct type, as well as provide popular IDEs a hint to what the
type has changed to.
Thanks,
Dominic
A feature I'd quite like to see is something similar to C# out arguments.
Which is an argument provided empty to a function (or with a value to be
ignored) that the function must write to before returning.Normally this wouldn't be necessary since you can do this anyway by passing
by reference, however I would like to make the same case for it that was
made for return types.A possible syntax to differ from C# might be:
function read(string ^$bytes, int length): int
{}
The arrow indicating that a value will be written to the argument.
Another case for this is the fact it is unfeasible to provide a type hint
for reference arguments because if the provided var is null or newly
created it will throw an error.Using type hints on outputs will both validate that the populating value is
of the correct type, as well as provide popular IDEs a hint to what the
type has changed to.Thanks,
Dominic
I don't see this being useful enough for adding a new syntax. I always
thought that "out" params in C-family languages was a hack and should be
avoided if possible. Newer C++ libraries tend to return tuples instead,
don't they? Most of the time people just return an array of values in
PHP code I've seen.