Mpdf: count(): Parameter must be an array or an object that implements Countable

Created on 18 Jan 2018  路  4Comments  路  Source: mpdf/mpdf

I found this bug / would like to have this new functionality

When generating the PDF I get the following error:

PHP Warning: count(): Parameter must be an array or an object that implements Countable in XXX/vendor/mpdf/mpdf/src/Mpdf.php on line 25892

Please add a check if variable is an array or object before.

This is mPDF and PHP version and environment (fpm/cli etc) I am using

7.0.3

missing sample / test notices-warnings wontfiworksforme

Most helpful comment

I am getting a similar issue with PHP 7.2 installations - I think there are some new restrictions with this version. PHP <= 7.1 seems to be okay.

I get this error at vendor\mpdf\mpdf\classes\ttfontsuni.php line 613 where you see

for ($i = 0; $i < count($psName); $i++) {

In this case $psName is a string so the problem is fixed with strlen()

for ($i = 0; $i < strlen($psName); $i++) {

This might give some clue as to the cause elsewhere. However, I'm still struggling with this as after I fixed it and then reverted there error did not come back - so I must have some caching somewhere as well!!

All 4 comments

See also #562 and #595. Could you provide a small example that let us reproduce this exactly?

How is Mpdf instantiated in your setup?
Which html is feeded into mPDF, such that it triggers this error? (please provide a _small_ html example)

This is useful for reproducing your case, and allows to create the unit test for this issue. Thanks!

I am getting a similar issue with PHP 7.2 installations - I think there are some new restrictions with this version. PHP <= 7.1 seems to be okay.

I get this error at vendor\mpdf\mpdf\classes\ttfontsuni.php line 613 where you see

for ($i = 0; $i < count($psName); $i++) {

In this case $psName is a string so the problem is fixed with strlen()

for ($i = 0; $i < strlen($psName); $i++) {

This might give some clue as to the cause elsewhere. However, I'm still struggling with this as after I fixed it and then reverted there error did not come back - so I must have some caching somewhere as well!!

@geofftech based on the class path you are using 6.x version of mPDF not compatible with PHP 7.1+.

This is already fixed in mPDF 7.x

Tengo un problema similar con las PHP 7.2instalaciones: creo _que_ hay algunas restricciones nuevas con esta versi贸n. PHP <= 7.1parece estar bien

Recibo este error en la vendor\mpdf\mpdf\classes\ttfontsuni.phpl铆nea 613 donde ves

for ($i = 0; $i < count($psName); $i++) {

En este caso $psNamees una cadena por lo que el problema se soluciona constrlen()

for ($i = 0; $i < strlen($psName); $i++) {

Esto podr铆a dar alguna pista sobre la causa en otro lugar. Sin embargo, todav铆a estoy luchando con esto, ya que despu茅s de que lo arregl茅 y luego revirt铆 all铆, el error no volvi贸, 隆隆as铆 que tambi茅n debo tener algo de almacenamiento en cach茅 en alg煤n lugar !!

Funciona , solo hay que tener cuidado al momento de desplegar en servidor ya que es un problema que aun no esta solucionado por parte de los creadores de la libreria entonces tocaria volver a modificarlo cuando ya se haya desplegado

Was this page helpful?
0 / 5 - 0 ratings