Skip to content

Fix PHP 8.5 PDO deprecations, keep compatibility with older PHP - #25

Open
xaben wants to merge 1 commit into
roojs:masterfrom
xaben:fix/php85-pdo-deprecations
Open

Fix PHP 8.5 PDO deprecations, keep compatibility with older PHP#25
xaben wants to merge 1 commit into
roojs:masterfrom
xaben:fix/php85-pdo-deprecations

Conversation

@xaben

@xaben xaben commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Hi @roojs, we are trying to update to the newer PHP version, and we've run into quite a few deprecations coming from PDO_DataObject. Could you please review the below fix? Greatly appreciated.

PHP 8.5 deprecates driver-specific constants defined on the base PDO class in favor of the Pdo<Driver> subclasses added in PHP 8.4. Resolve PDO::MYSQL_ATTR_USE_BUFFERED_QUERY and DSN fragment option constants (eg. MYSQL_ATTR_INIT_COMMAND) conditionally so the library keeps working unchanged on PHP < 8.4 while avoiding the new deprecation notices.

Also add #[AllowDynamicProperties] to several classes that were still missing it, which have been raising dynamic-property deprecations since PHP 8.2.

PHP 8.5 deprecates driver-specific constants defined on the base PDO
class in favor of the Pdo\<Driver> subclasses added in PHP 8.4. Resolve
PDO::MYSQL_ATTR_USE_BUFFERED_QUERY and DSN fragment option constants
(eg. MYSQL_ATTR_INIT_COMMAND) conditionally so the library keeps working
unchanged on PHP < 8.4 while avoiding the new deprecation notices.

Also add #[AllowDynamicProperties] to several classes that were still
missing it, which have been raising dynamic-property deprecations since
PHP 8.2.
@roojs

roojs commented Aug 28, 2026

Copy link
Copy Markdown
Owner

I've released a new version which fixes the constants - we now only accept the PHP8.4 constants now

For the dynamic property, could you elicit why that is needed because the AI analysis I did could not work out why um that would be justified. (note there was a few fixes to add named properties to a few classes)

@xaben

xaben commented Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

@roojs Thank you for the very quick turn around, this unblocks us.

As for the "AllowDynamicProperties", I've rechecked the usage and manually confirmed what the AI came back with, these are the places that do create dynamic properties (the last one might be not needed, if we were to validate the keys being passed in):

  • PDO_DataObject_Join — $this->_join .= $jadd; (line 530) and $this->_join .= "..."; (line 534). _join is never declared on this class — real dynamic property.
  • PDO_DataObject_Introspection (abstract base) — $this->last_query = ''; (line 83). last_query is never declared anywhere in the class or its subclasses — real dynamic property. Fixing the base class is correct since oci/pgsql/sqlite subclasses inherit the attribute.
  • PDO_DataObject_Links — the constructor does foreach ($cfg as $k => $v) { $this->$k = $v; } (line 99). Since $cfg is caller-supplied and $k isn't restricted to the declared properties (do, load, scanf, printf, cached, apply, links), any other key creates a dynamic property.

@roojs

roojs commented Aug 28, 2026

Copy link
Copy Markdown
Owner

try the new build - i think it should fix both - links is just using univeral ctor - so filtering fixes it, and join - just added the _join property - also split the exceptions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants