Skip to content

\PDO\Mysql constants do not resolve correctly if pdo_mysql is not installed #14041

@longwave

Description

@longwave

Bug report

With the test script from the playground I get different results depending on whether pdo_mysql is installed or not:

$ php -m|grep pdo_mysql
pdo_mysql
$ vendor/bin/phpstan analyze --no-progress phpstan-test.php

                                                                                                                        
 [OK] No errors                                                                                                         

If I then disable the extension:

$ php -m|grep pdo_mysql
$ vendor/bin/phpstan analyze --no-progress phpstan-test.php
 ------ ------------------------------------------------------------------------------------------------------------------------------------------------ 
  Line   phpstan-test.php                                                                                                                                
 ------ ------------------------------------------------------------------------------------------------------------------------------------------------ 
  9      Array has 3 duplicate keys with value 0 (\Pdo\Mysql::ATTR_USE_BUFFERED_QUERY, \Pdo\Mysql::ATTR_FOUND_ROWS, \Pdo\Mysql::ATTR_MULTI_STATEMENTS).  
         🪪  array.duplicateKey                                                                                                                          
 ------ ------------------------------------------------------------------------------------------------------------------------------------------------ 


                                                                                                                        
 [ERROR] Found 1 error                                                                                                  

If I try to use @phpstan-ignore I get a similar problem but the other way round.

This is problematic for the Drupal project where different users in different environments may run PHPStan with and without the extension being available.

Code snippet that reproduces the problem

https://phpstan.org/r/6758eb33-677d-4125-88ac-61df8f96f1ce

Expected output

$ php -m|grep pdo_mysql
$ vendor/bin/phpstan analyze --no-progress phpstan-test.php

                                                                                                                        
 [OK] No errors                                                                                                         

Did PHPStan help you today? Did it make you happy in any way?

PHPStan has fixed many bugs and given developers more confidence in the Drupal codebase - thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions