Skip to content
This repository was archived by the owner on Jul 8, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
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
30 changes: 30 additions & 0 deletions src/Polyfill/Errors.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Eloquent\Phony\Polyfill;

class Errors
{
/**
* Clear the last runtime error.
*
* Prevents feature detection errors from leaking out into shutdown handlers
* that look at error_get_last().
*
* @return void
*/
public static function errorClearLast()
{
// https://github.com/symfony/polyfill/blob/ba249100f5/src/Php70/Php70.php#L52-L61
set_error_handler([__CLASS__, 'silentHandler']);
@trigger_error('');
restore_error_handler();
}

/**
* @return false
*/
public static function silentHandler()
{
return false;
}
}
13 changes: 13 additions & 0 deletions src/Reflection/FeatureDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Eloquent\Phony\Reflection;

use Eloquent\Phony\Polyfill\Errors;
use Eloquent\Phony\Reflection\Exception\UndefinedFeatureException;
use Exception;
use ReflectionClass;
Expand Down Expand Up @@ -186,6 +187,10 @@ public function standardFeatures()
return $detector->checkInternalClass('Error');
},

'error.clear.last' => function ($detector) {
return function_exists('error_clear_last');
},

'generator' => function ($detector) {
return $detector->checkInternalClass('Generator');
},
Expand Down Expand Up @@ -513,6 +518,14 @@ public function checkStatement($source, $useClosure = true)
// @codeCoverageIgnoreEnd
}

if (false === $result && empty($e)) {
if ($this->isSupported('error.clear.last')) {
error_clear_last();
} else {
Errors::errorClearLast();
}
}

error_reporting($reporting);

return true === $result;
Expand Down