Skip to content

PHPCompatibility thinks my "mysql_*" static method is builtin mysql_ function. #207

@C-Duv

Description

@C-Duv

TL;DR: PHPCompatibility thinks my Foo::mysql_bar() is one of Original MySQL API's mysql_* functions.

Consider the following PHP code:

<?php
class Foo {
    static public function mysql_bar() {
        echo __METHOD__ . '() called';
    }
}
Foo::mysql_bar(); // Prints: Foo::mysql_bar() called

PHP_CodeSniffer+PHPCompatibility tested using:

cd $(mktemp -d)

# Install using Composer
echo '{}' > composer.json
composer config prefer-stable true
composer require --dev \
    'squizlabs/php_codesniffer:*' \
    'wimg/php-compatibility:*' \
    'simplyadmire/composer-plugins:@dev'

# Install "PHPCompatibility coding standard" in PHP_CodeSniffer
mkdir --parents vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility
cp -R vendor/wimg/php-compatibility/* vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PHPCompatibility

# Place sample code
cat > test_calling_userland_method_begining_with_mysql_.php << 'EOT'
<?php
class Foo {
    static public function mysql_bar() {
        echo __METHOD__ . '() called';
    }
}
Foo::mysql_bar(); // Prints: Foo::mysql_bar() called
EOT

# Run PHP_CodeSniffer
php ./vendor/bin/phpcs \
    --standard=PHPCompatibility \
    ./test_calling_userland_method_begining_with_mysql_.php

Generates the following report:

FILE: ...wf8deZFHDe/test_calling_userland_method_begining_with_mysql_.php
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 7 | ERROR | Extension 'mysql_' is deprecated since PHP 5.5 and
   |       | removed since PHP 7.0 - use mysqli instead.
----------------------------------------------------------------------

Time: 16ms; Memory: 4.5Mb

It is complaining about using mysql_ extension which I am not.

When modifying tested code to not use variable class:

[...]
(new Foo())->mysql_bar();

PHPCompatibility gives no output (ie. no compatibility issues).

Versions:

  • PHP 5.6.25-1+deb.sury.org~xenial+1 (cli)
    • with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
    • with Xdebug v2.4.0, Copyright (c) 2002-2016, by Derick Rethans
  • PHP_CodeSniffer v2.6.2
  • wimg/php-compatibility v7.0.4

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions