Due to the desire to maintain compatibility with PHP, alternative runtimes such as HHVM set the PHP_VERSION
constant to something like 5.6.0-hhvm
(utilizing the PHP_EXTRA_VERSION
portion of the version typically used by distros). This makes it difficult to programmatically tell the difference between when code is running on HHVM, or on PHP. While it is possible to check for HHVM_VERSION
in addition to PHP_VERSION
to definitively check that you are on HHVM, this doesn't scale to further implementations such as HippyVM and others.
This RFC proposes to add a new constant that explicitly denotes the engine being used, and more importantly makes it's use as such part of the language spec.
This proposal is very simple:
PHP_ENGINE
constant that will contain an identifier for the engine running the current code. For PHP this would be 'php', while HHVM would use 'hhvm', etc.
Additionally, we _could_ introduce a further constants to pair with the new PHP_ENGINE
constant: PHP_ENGINE_VERSION
(or perhaps PHP_ENGINE_*_VERSION
and PHP_ENGINE_VERSION_ID
) that would be used to store the engines own version details — with the standard PHP_(*_)VERSION(_ID)
constants continuing to be used for compatibility.
This would effectively make the original' PHP_VERSION
and related constants indicate what version of the language spec the runtime conforms to, with PHP being the reference implementation and therefore both values would be identical. This should be standardized in the specification as the expected behavior.
To conform to the PHP spec an alternative implementation must:
PHP_ENGINE
to a string identifying the alternative runtimePHP_(*_)VERSION(_ID)
to the version of the language spec they conform toPHP_ENGINE_(*_)VERSION(_ID)
to the alternative runtimes versionFor example, for HHVM 3.11 to conform to the spec:
PHP_VERSION = 7.0.0 PHP_ENGINE = 'hhvm' PHP_ENGINE_VERSION = '3.11' PHP_VERSION_ID = 70000 PHP_MAJOR_VERSION = 7 PHP_MINOR_VERSION = 0 PHP_RELEASE_VERSION = 0 PHP_EXTRA_VERSION = '' PHP_ENGINE_VERSION_ID = 30110 PHP_ENGINE_MAJOR_VERSION = 3 PHP_ENGINE_MINOR_VERSION = 11 PHP_ENGINE_RELEASE_VERSION = 0 PHP_ENGINE_EXTRA_VERSION = ''
None, constants starting with PHP_
are considered reserved.
PHP 7.2
None
None
None
PHP_ENGINE
— A simple string denoting the runtime engine, e.g. php
or hhvm
PHP_ENGINE_VERSION
— the full version of the engine, e.g. 3.8.13-dev
PHP_ENGINE_VERSION_ID
— the full version as an int, e.g. 30813
PHP_ENGINE_MAJOR_VERSION
— the major version of the engine, e.g. 3
PHP_ENGINE_MINOR_VERSION
— the minor version of the engine, e.g. 8
PHP_ENGINE_RELEASE_VERSION
— the release version of the engine, e.g. 13
PHP_ENGINE_EXTRA_VERSION
— extra version info e.g. -dev
Voting is a simple 50%+1 majority as there are no language changes. Voting will close on September 23rd.
PHP_ENGINE
constant: https://github.com/php/php-src/compare/master...dshafik:rfc-php_engine_constantPHP_ENGINE(_*)_VERSION(_ID)
constants: https://github.com/php/php-src/compare/master...dshafik:rfc-php_engine_constant-extraAfter the project is implemented, this section should contain