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

Compatibility layer for PHP installations without PDO support #808

Closed
wants to merge 1 commit into from

Conversation

adamziel
Copy link

Even though DBAL currently offers non-PDO drivers, it depends on a number of PDO constants which renders it unusable if PHP was explicitly compiled without PDO. This PR is an attempt to shim PDO constants as stated in ticket DBAL-1156 (http://www.doctrine-project.org/jira/browse/DBAL-1156)

@adamziel adamziel changed the title Compatibility layer for PHP installations without PDO support - ticket D... Compatibility layer for PHP installations without PDO support Feb 28, 2015
@doctrinebot
Copy link

Hello,

thank you for creating this pull request. I have automatically opened an issue
on our Jira Bug Tracker for you. See the issue link:

http://www.doctrine-project.org/jira/browse/DBAL-1157

We use Jira to track the state of pull requests and the versions they got
included in.

@@ -20,7 +20,7 @@
namespace Doctrine\DBAL\Cache;

use Doctrine\DBAL\Driver\ResultStatement;
use PDO;
use Doctrine\DBAL\PDOCompat;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not simply providing a PDO class via something like following? Much simpler, much better compatibility:

{
    "autoload": {
        "classmap": [
            "path/to/PDO.php"
        ]
    }
}

@Ocramius Ocramius self-assigned this Feb 28, 2015
@adamziel
Copy link
Author

adamziel commented Mar 1, 2015

I updated this pull request to match your suggestion

* @link http://php.net/manual/en/pdo.constants.php
* @package Doctrine\DBAL
*/
class PDO
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defining this class with only the constants is a very bad idea IMO. It means that any project detecting the availability of PDO through a class_exists check will now think that PDO is available while it is not.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stof I think that's not a big problem for us.
While I agree with you on the risks, it is still for the little percentage of projects that want to use Doctrine DBAL without PDO, so the crowd being affected is actually pretty small.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it means that DBAL is now saying F*** you to any library trying to detect whether PDO is available to choose their implementation, thus forbidding users to use such library and DBAL together in a project. This seems a bad idea IMO, because the responsible for this incompatibility will be us

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stof actually I modified it to this form after @Ocramius specifically asked. Initially this PR was an additional class Doctrine\DBAL\PDOCompat and rest of the non-PDO-specific DBAL code refactored to use it instead of \PDO when referencing constants - what do you think about this approach?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stof the risk seems to be acceptable, tbh

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stof @adamziel @Ocramius can't we somehow make the registration of the shim class conditional on whether PDO is installed or not? Maybe by bootstrapping composer autoloader somehow (don't have enough knowledge about this).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@deeky666 looking again at this, I think it isn't worth supporting this approach anymore: we should just make ext-pdo a hard dependency and call it "done".

While removing the dependency is a nice-to-have, PDO is probably the ugliest API we can polyfill, riddled with poor design decisions, strange method signatures and behaviors.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creating this thing to only throw an exception is pretty much the same as the hard dependency.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creating such class could break any other library checking the existing of the PDO class and then trying to use something else than a constant from it when it exists. So I'm -1 on adding it.

@morozov
Copy link
Member

morozov commented May 2, 2017

I think it isn't worth supporting this approach anymore: we should just make ext-pdo a hard dependency and call it "done".

Why? Doctrine doesn't use anything from PDO besides constants and even this dependency can be eliminated by getting rid of usage of PDO:: constants in favor of Doctrine's own. If an app uses DBAL and doesn't support PDO it will have to require it even if it doesn't support it.

While removing the dependency is a nice-to-have, PDO is probably the ugliest API we can polyfill, riddled with poor design decisions, strange method signatures and behaviors.

Why is it needed to polyfill anything else then constants from PDO? This shim works perfectly, but just getting rid of their usage will be the right fix IMO.

@Ocramius
Copy link
Member

Ocramius commented May 2, 2017 via email

@Ocramius
Copy link
Member

Ocramius commented May 3, 2017

Closing: moving to #2709

@Ocramius Ocramius closed this May 3, 2017
lcobucci added a commit that referenced this pull request May 3, 2017
…dd-pdo-as-hard-dependency

Adding PDO as hard dependency as per discussion in #808
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants