From c5edf46c8eb60d56d3b331ca7c4c4c235b3164d0 Mon Sep 17 00:00:00 2001 From: Yenfry Herrera Feliz Date: Wed, 24 Jan 2024 08:18:41 -0800 Subject: [PATCH] fix: use dynamic class name instead of reference To prevent check errors in PHP versions below to 8, I am changing the check for if self::$socket is an instance of \Socket by using dynamic class name instead of direct reference. --- .../AbstractMonitoringMiddleware.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/ClientSideMonitoring/AbstractMonitoringMiddleware.php b/src/ClientSideMonitoring/AbstractMonitoringMiddleware.php index eed0529df5..d514e83558 100644 --- a/src/ClientSideMonitoring/AbstractMonitoringMiddleware.php +++ b/src/ClientSideMonitoring/AbstractMonitoringMiddleware.php @@ -224,18 +224,21 @@ protected function populateResultEventData( return $event; } - + /** - * Checks if the socket is created. + * Checks if the socket is created. If PHP version is greater or equals to 8 then, + * it will check if the var is instance of \Socket otherwise it will check if is + * a resource. * * @return bool Returns true if the socket is created, false otherwise. */ - private function isSocketCreated() + private function isSocketCreated(): bool { // Before version 8, sockets are resources // After version 8, sockets are instances of Socket if (PHP_MAJOR_VERSION >= 8) { - return (self::$socket instanceof \Socket); + $socketClass = '\Socket'; + return self::$socket instanceof $socketClass; } else { return is_resource(self::$socket); } @@ -252,7 +255,7 @@ private function isSocketCreated() */ private function prepareSocket($forceNewConnection = false) { - if (!$this->isSocketCreated() + if (!$this->isSocketCreated() || $forceNewConnection || socket_last_error(self::$socket) ) { @@ -303,4 +306,4 @@ private function unwrappedOptions() } return $this->options; } -} \ No newline at end of file +}