Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
LegendPJ opened this issue Nov 23, 2017 · 13 comments

Comments

@LegendPJ
Copy link

Hello,

I'm using the latest version of mpdf (7.0.2) with PHP 7.2 and I found a bug.
It's happening at line 5788 of Mpdf.php (very begining of the trimOTLdata() method) :

$len = count($cOTLdata['char_data']);

The problem is that $cOTLdata['char_data'] could be null in some cases, and PHP 7.2 doesn't allow count(null)

By changing this line to :

$len = $cOTLdata['char_data'] === null ? 0 : count($cOTLdata['char_data']);

... it solves the problem, but I don't know enough about the project to make a pull request.

Hope this will be helpful !

@finwe
Copy link
Member

finwe commented Nov 23, 2017

Can you please post your PHP/HTML code? I would like to know if the cause of this is not somewhere earlier in the code rather than just checking for NULL.

@LegendPJ
Copy link
Author

I've isolated a piece of my HTML/PHP code that doesn't work :

HTML :

<!DOCTYPE html>
<html>
    <head>
        <style>
            div, table {
              font-size: 8.5pt;
              font-family: "Arial";
            }
        </style>
    </head>
    <body>
    <div class="bill">
        <div class="header">
            <div class="logo">
                <img src="" />
            </div>
        </div>
    </div>
    </body>
</html>

PHP :

$mpdf = new Mpdf([
     'format' => 'A4',
     'margin_left' => 7,
     'margin_right' => 7,
     'margin_top' => 7,
     'margin_bottom' => 7,
     'margin_header' => 0,
     'margin_footer' => 3
]);

$mpdf->WriteHTML($html);

$mpdf->Output($file, Destination::FILE);

If I remove the following line : font-family: "Arial";, the warning doesn't show up anymore.

@treadmillian
Copy link

What happens if you try: font-family: Arial;

@LegendPJ
Copy link
Author

Exactly the same problem. I tried another font, but it doesn't work anymore.

@finwe
Copy link
Member

finwe commented Nov 30, 2017

Added the check, although I was not able to reproduce the issue.

@vukanac
Copy link

vukanac commented Dec 20, 2017

I got the same issue after upgrading to php7.2 on mac os x.

@finwe
Copy link
Member

finwe commented Dec 20, 2017

@vukanac Not particularly helpful. Show your library version and code snippet causing this. The check is not yet released IIRC.

@jonnsl
Copy link

jonnsl commented Jan 2, 2018

I'm having the same issue. It happens only when the CSS specifies a font that is not installed.
mpdf: 7.0.2
PHP: 7.2.0 ArchLinux

@Klap-in
Copy link
Contributor

Klap-in commented Jan 2, 2018

Last time when this issue was solved, the following test was added:
9ac8927
Is this test case working for you?
Can you provide a similar example case that reproduces your situation? Thanks!

@finwe
Copy link
Member

finwe commented Jan 3, 2018

I've released v7.0.3 where the check for NULL is incorporated.

@shubhamnarlawar77
Copy link

I am facing this issue while installing drupal-7.56. at line 1441 of "C:\xampp\htdocs\drupal\drupal-7.56\includes\form.inc)."
Is it the common error due to php v.7.2.3?

@Klap-in
Copy link
Contributor

Klap-in commented Mar 27, 2018

Please update to the last release of mpdf.
I expect it is solved in that release.

If it is not solved, than it is a similar issue popping up from different location in the code.
Please open in that case a new issue report and provide an example of php and html to allow reproducing the error. Thanks!

@shubhamnarlawar77
Copy link

Yeah sure i will do that.

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

No branches or pull requests

7 participants