====== PHP RFC: Add PHP Engine Identifier Constant ====== * Version: 0.2 * Date: 2016-02-03 * Author: Davey Shafik,davey@php.net * Status: Declined * First Published at: http://wiki.php.net/rfc/php_engine_constant ===== Introduction ===== 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.// ===== Proposal ===== This proposal is very simple: - Add a ''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. - Update the language spec to document that this constant is intended to contain a simple string denoting the engine running the code — it should *not* contain a version 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**: - Set ''PHP_ENGINE'' to a //string// identifying the alternative runtime - Set ''PHP_(*_)VERSION(_ID)'' to the version of the language spec they conform to - Set ''PHP_ENGINE_(*_)VERSION(_ID)'' to the alternative runtimes version For 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 = '' ===== Backward Incompatible Changes ===== None, constants starting with ''PHP_'' are considered reserved. ===== Proposed PHP Version(s) ===== PHP 7.2 ===== RFC Impact ===== ==== To SAPIs ==== None ==== To Existing Extensions ==== None ==== To Opcache ==== None ==== New Constants ==== - ''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'' ===== Vote ===== Voting is a simple 50%+1 majority as there are no language changes. Voting will close on September 23rd. * Yes * No ---- * Yes * No ===== Patches and Tests ===== * Simple patch for just ''PHP_ENGINE'' constant: https://github.com/php/php-src/compare/master...dshafik:rfc-php_engine_constant * With all the ''PHP_ENGINE(_*)_VERSION(_ID)'' constants: https://github.com/php/php-src/compare/master...dshafik:rfc-php_engine_constant-extra ===== Implementation ===== After the project is implemented, this section should contain - the version(s) it was merged to - a link to the git commit(s) - a link to the PHP manual entry for the feature ===== Rejected Features =====