rfc:php_engine_constant

PHP RFC: Add PHP Engine Identifier 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:

  1. 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.
  2. 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:

  1. Set PHP_ENGINE to a string identifying the alternative runtime
  2. Set PHP_(*_)VERSION(_ID) to the version of the language spec they conform to
  3. 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

  1. PHP_ENGINE — A simple string denoting the runtime engine, e.g. php or hhvm
  2. PHP_ENGINE_VERSION — the full version of the engine, e.g. 3.8.13-dev
  3. PHP_ENGINE_VERSION_ID — the full version as an int, e.g. 30813
  4. PHP_ENGINE_MAJOR_VERSION — the major version of the engine, e.g. 3
  5. PHP_ENGINE_MINOR_VERSION — the minor version of the engine, e.g. 8
  6. PHP_ENGINE_RELEASE_VERSION — the release version of the engine, e.g. 13
  7. 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.

Add PHP_ENGINE constant
Real name Yes No
bwoebi (bwoebi)  
davey (davey)  
diegopires (diegopires)  
galvao (galvao)  
gooh (gooh)  
hywan (hywan)  
kalle (kalle)  
leigh (leigh)  
marcio (marcio)  
mariano (mariano)  
mbeccati (mbeccati)  
mike (mike)  
nikic (nikic)  
ocramius (ocramius)  
stas (stas)  
svpernova09 (svpernova09)  
trowski (trowski)  
Final result: 8 9
This poll has been closed.

Add PHP_(*_)ENGINE(_ID) constants
Real name Yes No
ajf (ajf)  
bwoebi (bwoebi)  
davey (davey)  
diegopires (diegopires)  
galvao (galvao)  
gooh (gooh)  
hywan (hywan)  
kalle (kalle)  
leigh (leigh)  
marcio (marcio)  
mariano (mariano)  
mbeccati (mbeccati)  
mike (mike)  
nikic (nikic)  
ocramius (ocramius)  
stas (stas)  
trowski (trowski)  
Final result: 3 14
This poll has been closed.

Patches and Tests

Implementation

After the project is implemented, this section should contain

  1. the version(s) it was merged to
  2. a link to the git commit(s)
  3. a link to the PHP manual entry for the feature

Rejected Features

rfc/php_engine_constant.txt · Last modified: 2020/08/01 23:50 by carusogabriel