HHVM 4.68
HHVM 4.68 is released! This release marks the end of support for 4.61; HHVM 4.62–4.67 remain supported, as do the 4.32 and 4.56 LTS releases.
Highlights
- Hack no longer reports duplicate errors when an invalid type constant is referenced from another type constant.
Breaking Changes
- The
arraytype has been completely removed from HHVM. All arrays are now eithervarrayordarray, which are treated as separate incompatible types by both the typechecker and the runtime.- In recent HHVM versions, it had already been impossible to create
arrayvalues that are neithervarrayordarrayfrom Hack code, but some built-in functions could still return them. These have all been migrated to returnvarrayordarraynow. - The type
varray_or_darraywith either one or two generic parameters can be used to migrate code that needs to accept/return both types of arrays. However, usingContainerorKeyedContaineris usually preferable for any code that is intended to work with multiple array-like types. - Migrating
arraytype annotations tovarray_or_darrayis guaranteed to be safe in HHVM 4.68. In previous HHVM versions, it is safer to use<<__Soft>> varray_or_darray, as it is possible to havearrayvalues that are neithervarraynordarray, depending on the exact INI options. - Migrating
arraytype annotations tovarrayanddarray(or evenvecanddict) might be preferable, but it may cause runtime errors, possibly undetected by the typechecker (for values coming from untyped code including some built-ins). You can use<<__Soft>>to turn these errors into warnings. - Automated migrations for
arraytype annotations are available in HHAST v4.64.4.
- In recent HHVM versions, it had already been impossible to create
- The built-in functions
each,next,prevwere removed. Any other built-ins that use arrays’ “internal iterator” (current,key,reset,end) will also be removed soon.- Additional iterators and related classes were removed:
- all methods of
ArrayIteratorother thancurrent,key,next,rewind,valid AppendIteratorCachingIteratorCallbackFilterIteratorLimitIteratorMultipleIteratorParentIteratorRecursiveArrayIteratorRecursiveCachingIteratorRecursiveCallbackFilterIteratorRecursiveTreeIteratorSplFixedArraySplObjectStorage
- all methods of
- Additional iterators and related classes were removed:
- Attempting to merge arrays using the
+or+=operators now throws an exception. It had already been a typechecker error.- In recent HHVM versions, you can use the INI options
hhvm.hack_arr_compat_notices=trueandhhvm.hack_arr_compat_check_array_plus=trueto raise a notice.
- In recent HHVM versions, you can use the INI options
- Fixed the position at which the typechecker reports an error for a missing
type constant. This may require some
HH_FIXMEs to be moved. - Using
meth_callerwith a trait now raises a typechecker error. Runtime behavior hasn’t changed, HHVM currently allows constructing suchmeth_callerbut throws an exception when the method call is invoked. - By default, HHVM now raises a warning for any
switchstatements where none of the cases matched the provided value. In the future, this will be changed to throw an exception.- A
defaultbranch should be added to anyswitchstatements that intentionally don’t cover all possible cases. - Use the INI option
hhvm.throw_on_non_exhaustive_switch=0to temporarily disable this warning, orhhvm.throw_on_non_exhaustive_switch=2to enable the future behavior now (throw an exception).
- A
- By default, HHVM no longer allows user-defined error handlers to silence the
errors when function return type annotations are violated.
- This is only relevant if the INI option
hhvm.php7.engine_exceptionsis set tofalse. If this option istrue(default), return type violations throw aTypeErrorwhich can be caught, but it is never possible to continue execution in the same scope. - The INI option
hhvm.check_return_type_hintscan be used to temporarily reduce this to a recoverable error or a warning, but this option will be removed in the future.
- This is only relevant if the INI option
- By default, HHVM now raises a warning if any type annotations on properties
(static and instance variables) are violated. In the future, this will be
changed to throw an exception.
- The INI option
hhvm.check_prop_type_hintscan be used to temporarily disable the warning or to enable the future behavior now.
- The INI option
- Generic type parameters with upper bounds (
TFoo as FooBaseClass), when used as function parameter or return types, will now raise a warning if the upper bound is violated. This had already been a typechecker error, but previously ignored at runtime.- Note that only the upper bound is enforced at runtime, so code shouldn’t
rely on any assumptions stronger than that. In the above example, HHVM will
enforce that
TFoois an instance of some subclass ofFooBaseClass, but can’t enforce that it matches the exact type ofTFooin the given context, as generic types are erased at runtime. - Use the INI option
hhvm.enforce_generics_ub=0to temporarily disable this warning, orhhvm.enforce_generics_ub=2to enable the future behavior now (throw an exception).
- Note that only the upper bound is enforced at runtime, so code shouldn’t
rely on any assumptions stronger than that. In the above example, HHVM will
enforce that
- The INI option
hhvm.forbid_thrift_integer_values_out_of_range(used by the Thrift extension) has been removed.
Future Changes
- Arrays will soon no longer maintain an “internal iterator”, which should
reduce their memory usage. Any built-ins that depend on the internal iterator
are either already removed (
each,next,prev) or will be removed soon (current,key,reset,end).- Most users of these iteration APIs can be rewritten with
foreachloops, and would be much faster to boot. For cases that can’t be converted this way, you can useVec\keys($array)to get an array of keys andvec($array)to get an array of values and use aforloop over indices for these two arrays.
- Most users of these iteration APIs can be rewritten with
- The INI options mentioned above are expected to have stricter defaults and/or
be removed completely in the future:
hhvm.throw_on_non_exhaustive_switchhhvm.check_return_type_hintshhvm.check_prop_type_hintshhvm.enforce_generics_ub