Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use fully-qualified constant names for PHP versions (PHPMailer#2203)
This is a micro performance improvement. When PHP opcode generates opcodes, it can remove PHP version-specific `if` blocks if it sees `PHP_MAJOR_VERSION` or `PHP_VERSION_ID`. However, if the code belongs to a namespace, it cannot make that optimization because the code under namespace can declare the same constants. This PR updates such PHP constants to be fully-qualified (with back-slash), which enables PHP to make the improvement. To compare, this is the VLD opcode without fully-qualified constant names: ```php namespace X; if (\PHP_VERSION_ID < 80000) { echo "hi"; } ``` --> ``` line #* E I O op fetch ext return operands ------------------------------------------------------------------------------------- 5 0 E > FETCH_CONSTANT ~0 'X%5CPHP_MAJOR_VERSION' 1 IS_SMALLER_OR_EQUAL ~1 ~0, 8 2 > JMPZ ~1, ->4 6 3 > ECHO 'hi' 7 4 > > RETURN 1 ``` The same snippet, with the fully-qualified constants, PHP can simply eliminate and optimize the `if` block: ``` line #* E I O op fetch ext return operands ------------------------------------------------------------------------------------- 5 0 E > > JMPZ <true>, ->2 6 1 > ECHO 'hi' 7 2 > > RETURN 1 ```
- Loading branch information