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

Add HHVM to CI #37

Merged
merged 3 commits into from Feb 24, 2019
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+27 −3
Diff settings

Always

Just for now

wrap error_get_last() and error_clear_last() for compatibility

  • Loading branch information...
mike42 committed Feb 24, 2019
commit d2b2cd21ab13727d2dbda6a42f151d8443045d47
Copy path View file
@@ -17,11 +17,10 @@ class Image
public static function fromFile(string $filename) : RasterImage
{
// Attempt to catch the cause of any errors
error_clear_last();
self::clearLastError();
$blob = @file_get_contents($filename);
if ($blob === false) {
$e = error_get_last();
$error = (isset($e) && isset($e['message']) && $e['message'] != "") ? $e['message'] : "Check that the file exists and can be read.";
$error = self::getLastErrorOrDefault("Check that the file exists and can be read.");
throw new \Exception("Could not retrieve image data from '$filename'. $error");
}
return self::fromBlob($blob, $filename);
@@ -47,4 +46,29 @@ public static function create(int $width, int $height, int $impl = self::IMAGE_B
{
return BlackAndWhiteRasterImage::create($width, $height);
}
/**
* Call error_clear_last() if it exists. This is dependent on which PHP runtime is used.
*/
private static function clearLastError()
{
if (function_exists('error_clear_last')) {
error_clear_last();
}
}
/**
* Retrieve the message from error_get_last() if possible. This is very useful for debugging, but it will not
* always exist or return anything useful.
*/
private static function getLastErrorOrDefault(string $default)
{
if (function_exists('error_clear_last')) {
$e = error_get_last();
if (isset($e) && isset($e['message']) && $e['message'] != "") {
return $e['message'];
}
}
return $default;
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.