Skip to content

Conversation

@einenlum
Copy link
Contributor

Brief Summary of Changes

I ran into a very weird issue on my Laravel project. When the file doesn't exist, I get this error while trying to upload the file:

   WARNING  Trying to access array offset on null in vendor/cloudinary/cloudinary_php/src/Utils/FileUtils.php on line 141.

This is the culprit method:

public static function safeFileOpen(string $filename, string $mode, bool $useIncludePath = false)

What happens is that $err = error_get_last(); on line 139 returns NULL.

This is weird because when I forked the project and added tests locally to check how it behaves with a non-existing file, it worked as expected.

I discovered that it's because of how Laravel handles error handling. It uses a custom error handler which intercepts all errors (including warnings), and PHP's built-in error system has no clue about what happened. In the end, error_get_last returns NULL.

The library assumes error_get_last will contain an array with a message key. But this is not the case in every PHP environment and framework.

This PR adds a fallback to address this issue. It doesn't change default behavior.

How to reproduce?

Create a fresh Laravel app, install cloudinary php, add a cloudinary url, and try to upload a non-existing file.

I published a test app to show and test the behavior, here.

What does this PR address?

  • GitHub issue (Add reference - #XX)
  • Refactoring
  • New feature
  • Bug fix
  • Adds more tests

Are tests included?

  • Yes (but the bug cannot be reproduced without a Laravel environment)
  • [] No

Reviewer, please note:

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I ran the full test suite before pushing the changes and all of the tests pass.

@einenlum einenlum changed the title Fix/array offset error Fix array offset error in FileUtils when the file doesn't exist Sep 21, 2025
@const-cloudinary const-cloudinary merged commit 935aeb8 into cloudinary:master Sep 21, 2025
7 checks passed
@const-cloudinary
Copy link
Contributor

@einenlum Thank you for catching and fixing the issue!

@einenlum einenlum deleted the fix/array-offset-error branch September 21, 2025 11:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants