dompdf / php-svg-lib

SVG file parsing / rendering library
GNU Lesser General Public License v3.0
1.4k stars 77 forks source link

SVG Loading #40

Closed mmartel-opinionsystem closed 4 years ago

mmartel-opinionsystem commented 6 years ago

Since PHP 7.2 (probably 7+), getting this error when loading SVGs:

Error: count(): Parameter must be an array or an object that implements Countable on line 259 in lib/php-svg-lib/src/Svg/Document.php

My code to implement an SVG in DomPDF: <img src="image/certificat_adhesion/top_ribbon_portrait.svg" id="top_ribbon">

Image show up in PDF, but creates php error log entries due to error.

This is the problem: Line 259: if (count($this->attributes)) {

Should be:

if (count($attributes)) {

zacek commented 6 years ago

very similar issue:

PHP Notice:  Undefined offset: 0 in .../phenx/php-svg-lib/src/Svg/Tag/AbstractTag.php on line 146                                                                                                                                   
PHP Warning:  count(): Parameter must be an array or an object that implements Countable in .../phenx/php-svg-lib/src/Svg/Tag/AbstractTag.php on line 146

caused by preg_match_all that doesn't match and

...
146   if (count($match[0])) {
...
joaos-beyian commented 5 years ago

on line 259 in lib/php-svg-lib/src/Svg/Document.php, adding the following check

... 259 if (isset($this->attributes) && count($this->attributes)) { ...

before doing php count check should be done on variable first.

bsweeney commented 4 years ago

This cause of the OP's issue was addressed in 4909031bdabdc802cf49912d631690cb44b0240d.

@zacek your issue is an array handling issue but is different so I opened a new issue to address it.