Skip to content

Instantly share code, notes, and snippets.

@nickygerritsen
Created January 26, 2022 13:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickygerritsen/feb742d77040db092a1c5fa9228e5d4f to your computer and use it in GitHub Desktop.
Save nickygerritsen/feb742d77040db092a1c5fa9228e5d4f to your computer and use it in GitHub Desktop.
nikic-php-parser-7.4-fix.patch
From 773de16eb8fad6747064312f408fbb1e6c5e2759 Mon Sep 17 00:00:00 2001
From: Tyson Andre <tysonandre775@hotmail.com>
Date: Sat, 13 Jul 2019 17:05:09 -0400
Subject: [PATCH] Avoid notices in php 7.4 with hexdec/base_convert
This is made to avoid notices caused by
https://wiki.php.net/rfc/base_convert_improvements
(seen with `php -d error_reporting=E_ALL vendor/bin/phpunit`)
---
lib/PhpParser/Node/Scalar/String_.php | 4 ++--
lib/PhpParser/PrettyPrinter/Standard.php | 9 +++++++--
2 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/lib/PhpParser/Node/Scalar/String_.php b/lib/PhpParser/Node/Scalar/String_.php
index de6318d053..8a6d93a474 100644
--- a/lib/PhpParser/Node/Scalar/String_.php
+++ b/lib/PhpParser/Node/Scalar/String_.php
@@ -100,7 +100,7 @@ function($matches) {
if (isset(self::$replacements[$str])) {
return self::$replacements[$str];
} elseif ('x' === $str[0] || 'X' === $str[0]) {
- return chr(hexdec($str));
+ return chr(hexdec(substr($str, 1)));
} elseif ('u' === $str[0]) {
return self::codePointToUtf8(hexdec($matches[2]));
} else {
diff --git a/lib/PhpParser/PrettyPrinter/Standard.php b/lib/PhpParser/PrettyPrinter/Standard.php
index 78ee7d0032..97e9715a20 100644
--- a/lib/PhpParser/PrettyPrinter/Standard.php
+++ b/lib/PhpParser/PrettyPrinter/Standard.php
@@ -159,8 +159,13 @@ protected function pScalar_LNumber(Scalar\LNumber $node) {
return (string) $node->value;
}
- $sign = $node->value < 0 ? '-' : '';
- $str = (string) $node->value;
+ if ($node->value < 0) {
+ $sign = '-';
+ $str = (string) -$node->value;
+ } else {
+ $sign = '';
+ $str = (string) $node->value;
+ }
switch ($kind) {
case Scalar\LNumber::KIND_BIN:
return $sign . '0b' . base_convert($str, 10, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment