Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch resource check to class check for PHP v8 compatibility #2865

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/ClientSideMonitoring/AbstractMonitoringMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,23 @@ protected function populateResultEventData(
return $event;
}


/**
* Checks if the socket is created.
*
* @return bool Returns true if the socket is created, false otherwise.
*/
private function isSocketCreated()
{
// Before version 8, sockets are resources
// After version 8, sockets are instances of Socket
if (PHP_MAJOR_VERSION >= 8) {
return (self::$socket instanceof \Socket);
} else {
return is_resource(self::$socket);
}
}

/**
* Creates a UDP socket resource and stores it with the class, or retrieves
* it if already instantiated and connected. Handles error-checking and
Expand All @@ -235,7 +252,7 @@ protected function populateResultEventData(
*/
private function prepareSocket($forceNewConnection = false)
{
if (!is_resource(self::$socket)
if (!$this->isSocketCreated()
|| $forceNewConnection
|| socket_last_error(self::$socket)
) {
Expand Down