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

Fix unnecessary PHP warnings #135

Open
WM-Programator-3 opened this issue Aug 28, 2024 · 1 comment
Open

Fix unnecessary PHP warnings #135

WM-Programator-3 opened this issue Aug 28, 2024 · 1 comment

Comments

@WM-Programator-3
Copy link

Hello,

Not checking if file exists in class lib/OpenPayU/Oauth/Cache/OauthCacheFile.php causes PHP to throw errors.

Using @ doesn't suppress the errors if custom error handler is used, and since PHP 8, it is impossible to detect if @ was used in custom error handlers because of a "fix" of a bug that was widely accepted as a proper behaviour by the PHP community.

There is a simple fix to this problem - use PHP function file_exists() in get(), set() and invalidate() methods, which is the proper way of doing things in modern PHP.

The function is available since PHP 4 while openpayu_php requires PHP >= 5.3, which means there is no issue with compatibility.

Otherwise, users themselves would need to write some code specifically to suppress the warnings in you class in their error handlers.

Thanks.

@WM-Programator-3
Copy link
Author

Note:

Example of fixed methods:

    public function get($key)
    {
        return !file_exists($this->directory . md5($key)) ? null : unserialize(file_get_contents($this->directory . md5($key)));
    }
    public function invalidate($key)
    {
        return !file_exists($this->directory . md5($key)) || unlink($this->directory . md5($key));
    }

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

No branches or pull requests

1 participant