Skip to content

PHP 7.2 error: count(): Parameter must be an array or an object that implements Countable #21

Description

@michaelklopf

Since switching to PHP 7.2.4, we discovered this problem with our PDF merging tool, that makes use of this library.

Stacktrace:

[2018-04-26 16:40:24] local.ERROR: count(): Parameter must be an array or an object that implements Countable {"userId":123,"email":"test@test.com","exception":"[object] (ErrorException(code: 0): count(): Parameter must be an array or an object that implements Countable at /Users/username/dev/projectname/vendor/lynx39/lara-pdf-merger/src/LynX39/LaraPdfMerger/tcpdf/tcpdi_parser.php:486)
[stacktrace]
#0 /Users/username/dev/projectname/vendor/lynx39/lara-pdf-merger/src/LynX39/LaraPdfMerger/tcpdf/tcpdi_parser.php(486): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError(2, 'count(): Parame...', '/Users/username...', 486, Array)
#1 /Users/username/dev/projectname/vendor/lynx39/lara-pdf-merger/src/LynX39/LaraPdfMerger/tcpdf/tcpdi_parser.php(356): tcpdi_parser->decodeXrefStream(3979271, Array)
#2 /Users/username/dev/projectname/vendor/lynx39/lara-pdf-merger/src/LynX39/LaraPdfMerger/tcpdf/tcpdi_parser.php(195): tcpdi_parser->getXrefData()
#3 /Users/username/dev/projectname/vendor/lynx39/lara-pdf-merger/src/LynX39/LaraPdfMerger/tcpdf/tcpdi.php(122): tcpdi_parser->__construct('%PDF-1.6\
%\\xE2\\xE3\\xCF\\xD3\
...', '/Users/username...')
#4 /Users/username/dev/projectname/vendor/lynx39/lara-pdf-merger/src/LynX39/LaraPdfMerger/tcpdf/tcpdi.php(89): TCPDI->_getPdfParser('/Users/username...')
#5 /Users/username/dev/projectname/vendor/lynx39/lara-pdf-merger/src/LynX39/LaraPdfMerger/PdfManage.php(60): TCPDI->setSourceFile('/Users/username...')
#6 /Users/username/dev/projectname/app/Http/Controllers/ExportController.php(56): LynX39\\LaraPdfMerger\\PdfManage->merge('browser', '123-12-12333223...')
#7 [internal function]: App\\Http\\Controllers\\ExportController->App\\Http\\Controllers\\{closure}()
#8 /Users/username/dev/projectname/vendor/symfony/http-foundation/StreamedResponse.php(114): call_user_func(Object(Closure))
#9 /Users/username/dev/projectname/vendor/symfony/http-foundation/Response.php(367): Symfony\\Component\\HttpFoundation\\StreamedResponse->sendContent()
#10 /Users/username/dev/projectname/public/index.php(58): Symfony\\Component\\HttpFoundation\\Response->send()
#11 /Users/username/.composer/vendor/laravel/valet/server.php(147): require('/Users/username...')
#12 {main}
"}

The line in tcpdi_parser.php is this one:

    } elseif (($key == '/Index') AND ($v[0] == PDF_TYPE_ARRAY AND count($v[1] >= 2))) {

count($v[1] >= 2) is the cause of error here.

PHP 7.2 Backward incompatible changes:

http://php.net/manual/en/migration72.incompatible.php

The count() functions need to be replaced, or the objects used in them need to be Countable.

I don't have a solution to drop here yet. Any ideas, why the count is there?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions