Skip to content

Commit

Permalink
Fix for PHP 7.2/8.0: Explicitly check STDOUT/STDERR stream constants …
Browse files Browse the repository at this point in the history
…to be defined

These constants are only available when running PHP from CLI.
With PHP 7.2 there were deprecation warnings and with PHP 8 full errors for checking is_resource on these undefined constants (when not executed from CLI).
  • Loading branch information
Atanamo committed Oct 23, 2022
1 parent e987cae commit c5b3f4d
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/SimpleOutputTracer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

/**
* Simple implementation of the tracing interface that outputs any text to STDOUT/STDERR.
* Falls back to `echo`, if no STDOUT/STDERR streams do not exist.
* Falls back to `echo`, if STDOUT/STDERR streams do not exist.
*/
class SimpleOutputTracer extends AbstractTracer {

Expand All @@ -21,7 +21,7 @@ class SimpleOutputTracer extends AbstractTracer {

/**
* Returns the given text as line to be printed.
*
*
* @uses static::INDENT to indent the text.
* @uses static::EOL to end the line.
*
Expand All @@ -34,14 +34,14 @@ public function getLine($text) {

/**
* Prints the given text to STDOUT.
*
*
* @uses SimpleOutputTracer::getLine() to format the text as output line.
*
* @param string $text The text to print. Optional
* @return void
*/
public function writeLine($text='') {
if (is_resource(STDOUT)) {
if (defined('STDOUT') AND is_resource(STDOUT)) {
fwrite(STDOUT, $this->getLine($text));
} else {
echo $this->getLine($text);
Expand All @@ -55,7 +55,7 @@ public function writeLine($text='') {
* @return void
*/
public function writeErrLine($text='') {
if (is_resource(STDERR)) {
if (defined('STDERR') AND is_resource(STDERR)) {
fwrite(STDERR, $this->getLine($text));
} else {
echo $this->getLine($text);
Expand Down

0 comments on commit c5b3f4d

Please sign in to comment.