-
Notifications
You must be signed in to change notification settings - Fork 20
UX: Add Crate\PDO\PDOCrateDB as a better export symbol
#145
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
Conversation
309d333 to
79a8cf2
Compare
1ba3e58 to
d9d97b2
Compare
examples/insert_basic.php
Outdated
| // Connect to CrateDB. | ||
| use Crate\PDO\PDO as CratePDO; | ||
| $connection = new CratePDO("crate:localhost:4200", "crate"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thoughts
Autoloading, maybe like pdo-via-oci8 is doing it would be nice.
Importing CrateDB PDO's PDO class into the main namespace
Writing only use Crate\PDO\PDO here is a bad idea, and code validators will complain about it, because PDO is already defined in the main namespace - it is PHP's native PDO interface class.
For example, Scrutinizer reports 1:
This use statement conflicts with another class in this namespace,
PDO. Consider defining an alias.
Not importing CrateDB PDO's PDO class
Currently, when not importing Crate\PDO\PDO, new PDO("crate:localhost:4200") will obviously fail like:
PHP Fatal error: Uncaught PDOException: could not find driverProposal
My proposal is to automatically load the driver reference. However, it might not be possible, because regular PDO drivers are written in C/C++.
References
- https://www.reddit.com/r/PHP/comments/uiwlo1/is_it_possible_to_write_a_pdo_driver_in_pure_php/
- https://stackoverflow.com/questions/74665000/register-class-as-pdo-driver
Footnotes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With d9d97b2, I've added a convenience import symbol Crate\CratePDO, which does not suffer from the import conflict outlined above. Beforehand, I tried a deprecation path, but it proved to be too cumbersome. This variant is much more compact and non-invasive.
Crate\CratePDO as a better import symbol. Documentation: Add two standalone example programs about insert variants.
seut
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting findings, didn't know that this results in a conflict even when imported with full namespace. Shouldn't we deprecate Crate\PDO then?
Findings
State of the onionThe conflict is only there when you import the ImprovementsIt is really only about not using the identical symbol Outlook / conclusion
Having a namespace called |
I see, thanks for the clarification. Still I would favour that we only provide one solution in the long term to avoid complexity (maintenance) and user confusion. So I'd vote for deprecating |
We do need a namespace for the code anyway, and I think the namespace So, if we agree to rename that class gracefully, we can still discuss the name. I used If we do it that way, I will expand this patch, by:
Footnotes |
Crate\CratePDO as a better import symbol. Documentation: Add two standalone example programs about insert variants.Crate\PDO\PDOCrateDB as a better import symbol. Documentation: Add two standalone example programs about insert variants.
|
I've just renamed the new proposed class name to |
Crate\PDO\PDOCrateDB as a better import symbol. Documentation: Add two standalone example programs about insert variants.Crate\PDO\PDO to Crate\PDO\PDOCrateDB
My fault, I meant
Sound good, thanks! |
|
Because GH-146 is already stacked on top of this patch, and I don't see any chance to get out of this dilemma, in order to conduct the renaming beforehand, without getting serious merge conflicts later. So, I am integrating those two patches beforehand, and will conduct the renaming on behalf of a subsequent patch. |
Reason: Importing `Crate\PDO\PDO` without alias into the main namespace collides with PHP's native `PDO` class.
Crate\PDO\PDO to Crate\PDO\PDOCrateDBCrate\PDO\PDOCrateDB as a better export symbol
Crate\PDO\PDOCrateDB as a better export symbolCrate\PDO\PDOCrateDB as a better export symbol
Crate\PDO\PDOCrateDBas a better export symbol, in order to avoid name collisions with PHP's nativePDOclass, when imported into the main namespace without an alias.