-
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": "[email protected]"
}
],
"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 ?
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