-
Notifications
You must be signed in to change notification settings - Fork 147
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
Global namespace collision "Error" #104
Comments
What project defined an Error class? |
Our own software uses an Error class, which does not extend Exception. |
Okay, the best solution I can think of that will fix the problem immediately is to make sure your |
@paragonie-scott thank you for the prompt response. We use an autoloader to include the Error class only when needed. So including it prior to vendor/autoload.php goes against our internal development rules. For now, we have downgraded ramsay/uuid to 3.2, which does not make use of paragonie/random_compat yet. This will also prevent the issue temporarily for us. |
Note that 3.2 runs the risk of encountering this problem: ramsey/uuid#80 |
Yes, thank you for pointing that out. That was the reason for upgrading, although we have not detected UUID v4 collisions, yet. We are nowhere near generating that amount of UUIDs in PHP yet. We leverage PostgreSQL's UUID generator as well as client-side UUID generators. |
If you're using PostgreSQL and client-side code to generate UUIDs, then you probably won't run into the collision problem. The collision problem occurs when you are using OpenSSL in PHP running in an forked environment (i.e. Apache, FPM) to generate UUIDs. |
It sounds like this was resolved on your end, but I'd like to leave this issue open with a general commentary in case someone else encounters the same problem. The function of any polyfill library is to expose the new way of doing things on platforms that don't have those features. The purpose of any polyfill library is to enable developers to write code the new way even in environments that don't currently offer the capability to do things the new way out of the box. If your code defines an The workaround is to import random_compat after your custom
|
@paragonie-scott: You might want to check for |
Yes. Would ensure there's no custom |
e3753fe Does that look good? |
I think we should error out instead of extending If you define a custom |
I'd write it like that: if (!class_exists('Error')) {
class Error extends Exception { }
} else if (!is_subclass_of('Error', 'Exception')) {
throw E_FATAL;
}
if (!class_exists('TypeError')) {
class TypeError extends Error { }
} else if (!is_subclass_of('TypeError', 'Error')) {
throw E_FATAL;
} That should ensure it's always the same type hierarchy. |
I've been thinking about this for a while, and I think the solution is "document this in the README" and not try to handle these corner cases. |
As soon as I upgraded from ramsey/uuid 3.2 to 3.3 via composer, my servers started reporting the following PHP Fatal error:
PHP Fatal error: Call to undefined method Error::GetXML() in [script name]
Downgrading to 3.2, which also removes the prerequisite paragonie/random_compat v2.0.2, fixed the issue.
Issue appears to be in paragonie/random_compat extending Exception with the global name Error.
See:
https://github.com/paragonie/random_compat/blob/master/lib/error_polyfill.php
Cheers.
The text was updated successfully, but these errors were encountered: