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
Type hinting variadic arguments #4858
Comments
The runtime doesn't have full support for variadics yet (they can't be typed). The main concern is that in PHP 5.6 type-checking a variadic requires looping over the variadic array to check each argument. We plan to add support for this, but in the meantime if you want to use strict mode with variadics you'll need to add an function foo(
int $arg1,
bool $arg2,
/* HH_FIXME[4033]: variadic + strict */ ...$args
): string {
// ...
} |
HHVM does not support type hints for variadic arguments yet: facebook/hhvm#4858
Variadic params with type constraints are not supported by HHVM yet. See facebook/hhvm#4858
* upstream/master: Add note about facebook/hhvm#4858 bug HHVM bug #3651 fixed TimeZoneRegion methods to get available time-zone identifiers Fix failing test Add (plus|minus)(Months|Years)() methods to YearMonth
Had a chat with @dlreeves and @sgolemon; we're likely to:
|
I'm curious what's expensive about it? It seems like a basic O(N) problem, which shouldn't be too large, usually under 10 items. |
an O(n) problem at runtime is a large perf issue in the context of HHVM. |
True, but it seems like variadic arguments would be so sparse, that the cost incursion would be relatively minor. Coming from an outside perspective at least. |
It's also almost unnecessary in Hack (same exceptions as generics), and it would be weird to have different validation behavior for Hack and PHP. |
If PHP 7 supports it, you have to support it eventually. |
Any thoughts on how to remedy this? |
Btw, real world usage of variadic callables: https://github.com/lstrojny/functional-php/blob/master/src/Functional/Compose.php |
Closing - supported in '<?hh' since 3.13. Not supported in '<?php', filing a separate issue. |
@mschwager : HH_FIXME has no runtime affects; it only affects the Hack typechecker, and your code isn't hack. |
If we don't type hint variadic arguments we get this following type checker error.
If we do type hint them, the type checker error goes away, but then we get this runtime error.
What's the best way to go about this?
The text was updated successfully, but these errors were encountered: