-
Notifications
You must be signed in to change notification settings - Fork 100
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
Correct behaviour to match PHP 8.4 PDO returned types for connect and __construct for the internal pdo object #231
base: 6.x
Are you sure you want to change the base?
Conversation
@@ -111,7 +134,11 @@ public function establishConnection(): void | |||
// connect | |||
$this->profiler->start(__FUNCTION__); | |||
list($dsn, $username, $password, $options, $queries) = $this->args; | |||
$this->pdo = PDO::connect($dsn, $username, $password, $options); | |||
if ($this->driverSpecific) { | |||
$this->pdo = PDO::connect($dsn, $username, $password, $options); |
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.
I thought we don't need the connect method itself as this is implemented internally in the PDO.
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.
I was looking at the final release of the new PDO
PDO::__construct()
always returns PDO and PDO::connect()
returns Pdo\{driver} or PDO depending on available drivers
So if you use ExtendedPdo::getPdo()
you would get the correct typed object.
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.
That behaviour of PDO is expected. But in our case we are not calling the parent construct.
I'm getting this error when trying to use this library on PHP 8.4 ( https://github.com/console-helpers/db-migration/actions/runs/12323306770/job/34398667606 ):
I'm hoping this PR will help with that. |
@aik099 what version of PHP are you using and what does your composer file look like? |
@srjlewis , I'm using PHP 8.4. The {
"name": "console-helpers/db-migration",
"description": "Database migrations made simple",
"keywords": ["database", "migration", "sqlite"],
"license": "BSD-3-Clause",
"authors": [
{
"name": "Alexander Obuhovich",
"email": "aik.bold@gmail.com"
}
],
"require": {
"php": ">=5.6",
"aura/sql": "^2.5 || ^3.0 || ^4.0 || ^5.0"
},
"require-dev": {
"aik099/coding-standard": "dev-master",
"yoast/phpunit-polyfills": "^2.0",
"phpspec/prophecy": "^1.10",
"console-helpers/prophecy-phpunit": "^3.0"
},
"autoload": {
"psr-4": {
"ConsoleHelpers\\DatabaseMigration\\": "src/DatabaseMigration/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\ConsoleHelpers\\DatabaseMigration\\": "tests/DatabaseMigration/"
}
},
"extra": {
"branch-alias": {
"dev-master": "0.1.x-dev"
}
}
} |
@aik099 you would need to change your composer to "require": {
"php": ">=5.6",
"aura/sql": "^2.5 || ^3.0 || ^4.0 || ^5.0||dev-6.x"
} this will use 6.x branch that is compatable with PHP 8.4. I awaitig #230 being merged which would allow swapping between aura/sql versions, this is only targeting 5.x branch but can be backported to previous version. but yes this PR would help aswell to some degree in your case. All this is due to PHP 8.4 introducing I have both of these PR's in my personal repo and can easily switch between versions. @harikt please could you review these PR's and tag the 6.x branch for release, it would be helpful for PHP 8.4 users. |
@srjlewis , thank you for an explanation. I now understand why it's failing. I'll wait for Aura/Sql 6.x release. We're not switching to PHP 8.4 this year. |
@srjlewis yes, I have been checking this. But I am not sure if we need this change or not. @koriym , @frederikbosch can you guys look into this and give some suggestion if we need this specific change ?
|
|
} | ||
|
||
public static function connect( | ||
string $dsn, | ||
?string $username = null, | ||
?string $password = null, | ||
?array $options = [], | ||
?array $options = null, |
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.
can't we actually use [] instead of null, this will also remove the usage of $options ??= [];
right ?
Both points of view are reasonable. On one hand, separating Aura.Sql options from PDO options clearly makes future maintenance and understanding the codebase easier. On the other, as @srjlewis notes, the current approach likely won’t cause immediate technical issues since PDO ignores unknown string-based options. It’s a matter of prioritizing long-term clarity versus practical immediacy. |
@koriym @harikt thanks for your input and concerns Just to explain other considerations of why I took this approch.
To address the main concerns.
|
PHP adding a static connect() method as a factory has created quite the mess. And the introduction of PDO subclasses changes the foundations on which Aura.Sql was built so many years ago. As @koriym says, "It’s a matter of prioritizing long-term clarity versus practical immediacy." That is, the big question is, does Aura.Sql need a more thorough rebuilding from the ground up on the new 8.4 changes? Let's say for 6.x the answer is "no" and that some shorter-term patching-over is the plan. If that's the case, then here are some observations and commentary, all up for discussion:
Seems like even a patching-over is a big deal. Your thoughts, all? |
Hi @pmjones Sorry I did miss the PdoInterface, my bad. As for DecoratedPdo, some direction would be great, I did think about it, but was not sure on direction. as for establlishConnection(), there is no offical releases with that name in yet so could be easily changed, and I think everyone has a different naming idea and I am not too fussed what it's called, just as long as everyone is happy with it, but personaly I would keep it public due to the fact it is the call users can use to force a connection. The current 6.x branch only uses one method of connecting within establlishConnection(), which I dont mind, this current PR was submitted separately, as it is not required or needed for the 6.x branch to work with PHP 8.4, I only submitted it for correctness, so I am not fussed if it is used or not, but is only for matching behavior. Line 114 in 820ea99
to $this->pdo = new PDO($dsn, $username, $password, $options) and not use driver spacific driver classes as this would allow use of the 6.x branch with all supported versions of PHP. I would also understand if version 6.x was rebuilt with PHP >= 8.4 in mind, but I would leave that to you guys as you know what direction you want go. I would like to see a agreed upon version of this lib for PHP 8.4 sooner than later, as users are starting to use PHP 8.4 and the 5.x branch crashes on PHP 8.4, my dev and staging enviroments are already PHP 8.4 and my production servers are 8.3, so the usage is already there. I do feel like I am on a one man mission to get this lib to be 8.4 ready, and it is not huge changes to do so, but I do feel it has been a up hill struggle to do so. So any input or help would be great to get this over the line. |
I have done some changes to keep the behaviour the same as the PDO calls with the correct returned types for the pdo object.
Thanks to @frederikbosch as I took some of the ideas from #228 (comment), hope you don't mind