HHVM 4.1.0
HHVM 4.1 is released! This release will be supported for 8 weeks; we aim to start publishing weekly releases shortly, however this will not change the lifecycle for HHVM 4.1.
New Features
- added the nulltype; this allows$foo is nullas an alternative to$foo === null, consistent with$foo is nonnull.
- added the nothing(bottom/empty) type.
- .hhand- .hackfiles are now supported in repo-authoritiative mode. We recommend using- .hackfiles.
- user attributes are now supported on type constants
- IDE integrations now better support .hackfiles
- added the disable_unsafe_block.hhconfigoption to ban// UNSAFE
- ReflectionProperty::getAttribute()and- ::getAttributes()are now supported
- Anonymous functions with inoutparameters are now supported in async functions
- shape string keys can now start with integers, as long as they are not entirely integers
Breaking Changes
These changes are mostly working towards removing references from the language,
and removing support for functions that can inspect or modify the caller, such
as compact() or extract()
- <?hhis no longer valid by itself; replace with- <?hh // partial;- hhast-migrate --explicit-partial-modecan be used for this change.
- the assume_php.hhconfigoption has been removed; it is always false.
- globalstatements (e.g.- global $foo) are no longer supported
- the disallow_array_cell_pass_by_refanddisallow_assign_by_refoptions have been removed; these behaviors are now errors
- it is now both a runtime error and a type error to access superglobals by
reference, e.g. &$_SERVERor&$GLOBALS['foo']
- by-ref use clauses for anonymous functions (e.g. function () use (&$foo) {}) are no longer supported
- is_array(),- is_object()and similar functions are no longer auto-imported to every namespace; use- hhast-migrate --no-namespace-fallback
- support for PHP files is disabled by default
- markup sections are no longer supported
- variable variables ($$foo) are no longer supported in the runtime.
- get_magic_quotes_gpc(),- get_magic_quotes_runtime(), and- set_magic_quotes_runtime()have been removed.
- The hhvm.enable_zend_sortingoption has been removed; when the sort order was undefined, this option would make HHVM match PHP5’s behavior, but this would use a slower algorithm
- the WDDX extension has been removed
- .phpt(PHP template) files are no longer supported in repo-authoritative mode.
- destructors are no longer supported or called
- a warning is now raised if too many arguments are passed to non-variadic functions
- an exception is thrown if functions are called with too few arguments
- invoking forward_static_call()now raises an error
- define()has been removed
- the execution (backtick) operator is no longer supported
- Variance is now enforced for whereconstraints
- this::is no longer used in- isor- asconstraints at generics make it unsafe
- stdClassis now final
- __PHP_Incomplete_Classis now final, does not typecheck, and is no longer directly instantiable
- func_get_args(),- func_get_arg(), and- func_num_args()have been removed.
- get_defined_vars()has been removed
- get_called_class()has been removed
- KeyedContainerkeys must now be- arraykey; this affects- Map,- ImmMap,- Set, and- ImmSet.
- variables called $php_errormsgor$http_response_headerare no longer special
- Calling instance methods statically or static methods as instance methods now raises a warning.
- array_keys()now only takes one argument
- undefined constants (‘barewords’) now always raise an error
- the pharextension has been removed, as HHVM does not support building phars and was no longer able to execute PHP phars.
- integers now wrap instead of overflowing to floats
- Closure::bindToand- Closure::callhave been removed; these were already typechecker errors
- recordis a reserved word in preparation for a new data structure type.
- functions must be declared at the top level, or directly inside a namespace block. For example, they can no longer be defined conditionally, or inside another function.
PHP Files
<?php now raises a runtime error; while PHP is no longer supported by HHVM,
it is still possible to allow the <?php tag by setting the
hhvm.enable_php=true INI setting.
We disabled it by default as executing PHP files with HHVM 4 tends to give confusing and misleading error messages due to changes around references; disabling support allows a much clearer error message to be provided.
Markup Sections
The parser no longer understands markup sections; they are both typechecker
and runtime errors. Relatedly, ?> is no longer recognized.
1
2
3
4
5
This is a leading markup section
<?php
// foo
?>
This is a markup section, but not a leading markup section
Shebang lines (e.g. #!/usr/bin/env hhvm) are still permitted as the first
line of a file.
Future Changes
- in 4.2, <?hhwill imply strict mode, instead of being an error
- filter_input()and- filter_array()will be removed in a future release
- the IPC and extension will be removed in a future release
- the session extension and $_SESSIONwill be removed in a future release
- declare()will be removed in a future release
- user streams and stream filters will be removed in a future release
- static locals will be removed in HHVM 4.2; a type checker error can be raised
by setting the disable_static_local_variables=trueoption in .hhconfig
- property types will be enforced in a future release
- The hhvm.hard_type_hintsoption will be removed; type hints will always be enforced (this has been the default behavior for some time).
- static closures will be removed in a future release; the
hhvm.hack.lang.phpism.disable_static_closuresINI setting can be used to disable support in 4.0
- Calling instance methods statically or static methods as instance methods will be an error in a future release. In 4.0, this raises a warning.
- Removed hackificator,augmented_types,remove_soft_types, andcompare_coverage.pyas they have been unmaintained for some time.
- Dynamic calls will not be allowed to take by-reference parameters; this can
be currently be enforced with the disallow_byref_dynamic_calls.hhconfigoption
Static Locals
Static local variables will no longer be supported - for example:
1
2
3
4
function foo(): void {
  static $foo = null;
  // ...
}
There are several approaches for replacing them:
- replace with <<__Memoize>>or<<__MemoizeLSB>>
- use instance properties
- use static properties; care is needed to make sure that self::orstatic::is used correctly; the behavior of static local variables dependeded on the caller, so this could not be inferred.
If the function is potentially recursive, you may need to copy the property into a local, so that deeper calls do not affect the value in their callers.
Property Type Enforcement
The hhvm.check_prop_type_hints INI setting can be used to enable runtime
enforcement of property types. This enables additional optimizations.
Valid values are:
- 1: raise a warning
- 2: raise a recoverable error
- 3: raises a non-recoverable error
We expect property type enforcement to be mandatory in a future version.