Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 22, 2025

Plan: Add PHP 8.5 compatibility for PDO MySQL attribute

  • Understand the current implementation and test structure
  • Modify lib/Varien/Db/Adapter/Pdo/Mysql.php line 402 to add PHP 8.5 compatibility check
  • Add explanatory comments about PHP 8.5 compatibility
  • Create a focused test to validate the new conditional logic
  • Run tests to ensure the change doesn't break existing functionality
  • Verify the change is minimal and follows coding standards
  • Code review completed - no issues found
  • Security scan completed - no vulnerabilities
  • Fix PHP CS Fixer errors (remove extra blank lines)
  • Fix PHPStan errors (add @phpstan-ignore for future class)

Summary of Changes

1. Core Implementation (lib/Varien/Db/Adapter/Pdo/Mysql.php)

Modified the _connect() method to check for the new PDO\MYSQL namespace before setting the ATTR_USE_BUFFERED_QUERY attribute:

if (class_exists('PDO\\MYSQL')) { // @phpstan-ignore class.notFound $this->_connection->setAttribute(\PDO\MYSQL::ATTR_USE_BUFFERED_QUERY, true); } else { $this->_connection->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true); }

Added comprehensive comments explaining:

  • Purpose: PHP 8.5 compatibility
  • Context: MySQL-specific constants may move to PDO\MYSQL namespace in PHP 8.5+
  • Benefit: Maintains backward compatibility with older PHP versions
  • PHPStan ignore comment for the future class reference

2. Test Coverage (tests/unit/Varien/Db/Adapter/Pdo/MysqlTest.php)

Added testPdoMysqlNamespaceCompatibility() test that:

  • Checks for PDO\MYSQL class existence
  • Validates correct constant usage based on PHP version
  • Ensures the conditional logic works correctly

3. Code Style Fixes

  • Removed extra blank lines before and after the conditional block to comply with PER-CS2.0 coding standards
  • Added @phpstan-ignore class.notFound annotation to suppress PHPStan warnings about the future PHP 8.5 class

Validation Results:

  • ✅ PHP syntax validated for both files
  • ✅ Test logic validated and confirmed to pass
  • ✅ Code review: No issues found
  • ✅ Security scan: No vulnerabilities
  • ✅ PHP CS Fixer: Fixed blank line issues
  • ✅ PHPStan: Added ignore annotation for future class
  • ✅ Changes are minimal and surgical (2 files, +38 lines, -3 lines)

Backward Compatibility:

  • ✅ Fully backward compatible with PHP < 8.5
  • ✅ Forward compatible with PHP 8.5+ if namespace changes occur
  • ✅ No breaking changes to existing functionality
Original prompt

The current implementation of the code at lib/Varien/Db/Adapter/Pdo/Mysql.php line 402 sets PDO's MYSQL_ATTR_USE_BUFFERED_QUERY attribute unconditionally. This might cause compatibility issues in PHP 8.5 if the PDO\MYSQL namespace and its constants change or are not available.

To address this, the following check should be added before setting the attribute:

if (class_exists('PDO\\MYSQL')) { $this->_connection->setAttribute(PDO\\MYSQL::ATTR_USE_BUFFERED_QUERY, true); } else { $this->_connection->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true); }

This change ensures that the existing constant PDO::MYSQL_ATTR_USE_BUFFERED_QUERY is used for older PHP versions, maintaining backward compatibility. It also accounts for the potential new PDO\\MYSQL namespace that might exist in PHP 8.5.

Please include comments explaining the purpose of this check to future developers, with a note on its relevance to PHP 8.5 compatibility.

This pull request was created from Copilot chat.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@sreichel
Copy link
Contributor

if class_exists ....

Copilot AI and others added 2 commits December 22, 2025 16:14
Co-authored-by: addison74 <8360474+addison74@users.noreply.github.com>
Co-authored-by: addison74 <8360474+addison74@users.noreply.github.com>
@github-actions github-actions bot added Component: lib/Varien Relates to lib/Varien Component: lib/* Relates to lib/* phpunit labels Dec 22, 2025
Copilot AI changed the title [WIP] Add compatibility check for PDO MYSQL attributes Add PHP 8.5 compatibility for PDO::MYSQL_ATTR_USE_BUFFERED_QUERY Dec 22, 2025
Copilot AI requested a review from addison74 December 22, 2025 16:18
@addison74
Copy link
Contributor

@copilot - fix PHP CS Fixer (new lines before and after the code) and PHPStan errors.

…lock Co-authored-by: addison74 <8360474+addison74@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 22, 2025

@copilot - fix PHP CS Fixer (new lines before and after the code) and PHPStan errors.

Fixed in fd48c3f - removed extra blank lines before and after the conditional block to comply with PER-CS2.0 coding standards.

Co-authored-by: addison74 <8360474+addison74@users.noreply.github.com>
@github-actions
Copy link
Contributor

github-actions bot commented Dec 22, 2025

Test Results

967 tests  +1   959 ✅ +1   16s ⏱️ ±0s
213 suites ±0     8 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit 0d5dc14. ± Comparison against base commit b74526a.

♻️ This comment has been updated with latest results.

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

Labels

Component: lib/Varien Relates to lib/Varien Component: lib/* Relates to lib/* phpunit

3 participants