From fa9c13cefdc9349c045fd13603533f61474984ed Mon Sep 17 00:00:00 2001 From: Ayesh Karunaratne Date: Thu, 26 Nov 2020 01:27:52 +0700 Subject: [PATCH] Use fully-qualified constant names for PHP versions (#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 , ->2 6 1 > ECHO 'hi' 7 2 > > RETURN 1 ``` --- src/PHPMailer.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/PHPMailer.php b/src/PHPMailer.php index c8fc1a82..6592298d 100644 --- a/src/PHPMailer.php +++ b/src/PHPMailer.php @@ -1462,7 +1462,7 @@ class PHPMailer { if ( 'smtp' === $this->Mailer - || ('mail' === $this->Mailer && (PHP_VERSION_ID >= 80000 || stripos(PHP_OS, 'WIN') === 0)) + || ('mail' === $this->Mailer && (\PHP_VERSION_ID >= 80000 || stripos(PHP_OS, 'WIN') === 0)) ) { //SMTP mandates RFC-compliant line endings //and it's also used with mail() on Windows @@ -1474,8 +1474,8 @@ class PHPMailer //Check for buggy PHP versions that add a header with an incorrect line break if ( 'mail' === $this->Mailer - && ((PHP_VERSION_ID >= 70000 && PHP_VERSION_ID < 70017) - || (PHP_VERSION_ID >= 70100 && PHP_VERSION_ID < 70103)) + && ((\PHP_VERSION_ID >= 70000 && \PHP_VERSION_ID < 70017) + || (\PHP_VERSION_ID >= 70100 && \PHP_VERSION_ID < 70103)) && ini_get('mail.add_x_header') === '1' && stripos(PHP_OS, 'WIN') === 0 ) { @@ -4526,13 +4526,13 @@ class PHPMailer $privKey = openssl_pkey_get_private($privKeyStr); } if (openssl_sign($signHeader, $signature, $privKey, 'sha256WithRSAEncryption')) { - if (PHP_MAJOR_VERSION < 8) { + if (\PHP_MAJOR_VERSION < 8) { openssl_pkey_free($privKey); } return base64_encode($signature); } - if (PHP_MAJOR_VERSION < 8) { + if (\PHP_MAJOR_VERSION < 8) { openssl_pkey_free($privKey); }