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

php8 Zend_Log compatibility fixes #107

Merged
merged 3 commits into from
Oct 1, 2021
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: 16 additions & 3 deletions packages/zend-log/library/Zend/Log/Writer/Stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,23 @@ public function __construct($streamOrUrl, $mode = null)
}

$this->_stream = $streamOrUrl;
} else {
} else if (is_string($streamOrUrl) || is_array($streamOrUrl)) {
if (is_array($streamOrUrl) && isset($streamOrUrl['stream'])) {
$streamOrUrl = $streamOrUrl['stream'];
}

if (! $this->_stream = @fopen($streamOrUrl, $mode, false)) {
// catch and ignore ValueError which PHP 8.0+ may throw on invalid values passed to internal function
try {
$this->_stream = @fopen($streamOrUrl, $mode, false);
} catch (ValueError $e) {}

if (! $this->_stream) {
// require_once 'Zend/Log/Exception.php';
$msg = "\"$streamOrUrl\" cannot be opened with mode \"$mode\"";
throw new Zend_Log_Exception($msg);
}
} else {
throw new Zend_Log_Exception('Input is not a stream or url');
}

$this->_formatter = new Zend_Log_Formatter_Simple();
Expand Down Expand Up @@ -130,7 +137,13 @@ protected function _write($event)
{
$line = $this->_formatter->format($event);

if (false === @fwrite($this->_stream, $line)) {
$res = false;
// catch and ignore TypeError which PHP 8.0+ may throw when there was a problem with the stream (closed/unusable)
try {
$res = @fwrite($this->_stream, $line);
} catch (TypeError $e) {}

if (false === $res) {
// require_once 'Zend/Log/Exception.php';
throw new Zend_Log_Exception("Unable to write to stream");
}
Expand Down