tchwork / utf8

Portable and performant UTF-8, Unicode and Grapheme Clusters for PHP

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fatal error: Cannot redeclare iconv() during lint check

kenorb opened this issue · comments

Reproducible steps on empty folder:

$ composer require patchwork/utf8
  - Installing patchwork/utf8 (v1.3.1)
$ find vendor -name '*.php' -exec php -l {} ';'
No syntax errors detected in vendor/patchwork/utf8/src/Patchwork/Utf8/BestFit.php
Fatal error: Cannot redeclare iconv() in vendor//patchwork/utf8/src/Patchwork/Utf8/Bootup/iconv.php on line 21
Errors parsing vendor/patchwork/utf8/src/Patchwork/Utf8/Bootup/iconv.php
No syntax errors detected in vendor//patchwork/utf8/src/Patchwork/Utf8/Bootup/intl.php
Fatal error: Cannot redeclare mb_convert_encoding() in vendor/patchwork/utf8/src/Patchwork/Utf8/Bootup/mbstring.php on line 23
Errors parsing vendor//patchwork/utf8/src/Patchwork/Utf8/Bootup/mbstring.php
Fatal error: Cannot redeclare utf8_encode() in vendor/patchwork/utf8/src/Patchwork/Utf8/Bootup/utf8_encode.php on line 16
Errors parsing vendor//patchwork/utf8/src/Patchwork/Utf8/Bootup/utf8_encode.php
No syntax errors detected in vendor//patchwork/utf8/src/Patchwork/Utf8/Bootup.php
...
$ php --version
PHP 7.1.7 (cli) (built: Aug 20 2017 16:16:31) ( NTS )
$ php -m | grep iconv
iconv

If it's up to me, I could ignore these errors. However the project which I'm working on, we're using Jenkins CI which invokes the following Ant's base.xml file and it's scanning through all the PHP files to check for any syntax errors.

I believe the solution would be to check whether the iconv extension is already enabled, as other checks are in place in the same place for mbstring or xml. See: iconv.php, so the files can be properly invoked from the syntax checkers.

I'm using this library as per requirement from Underscore.php.

check whether the iconv extension is already enabled

that's on your side: your tool is linting the file, not the lib here (which already loads things conditionally...)