dompdf / php-font-lib

A library to read, parse, export and make subsets of different types of font files.
GNU Lesser General Public License v2.1
1.73k stars 256 forks source link

Code not working for PHP's strict mode #39

Closed oxygen closed 7 years ago

oxygen commented 8 years ago

If running with highest strictness level

set_error_handler(function($nSeverity, $strMessage, $strFilePath, $nLineNumber){
    throw new ErrorException($strMessage, /*nExceptionCode*/ 0, $nSeverity, $strFilePath, $nLineNumber);
}, /*E_STRICT*/ -1);

There are places where undefined array indexes default to 0 or something.

For example: \FontLib\BinaryStream::w($type, $data) [...]

for ($i = 0; $i < $type[1]; $i++) {
    $ret += $this->w($type[0], $data[$i]);
}

$data[$i] doesn't always exist.

Suggested fix:

      for ($i = 0; $i < $type[1]; $i++) {
        $ret += $this->w($type[0], isset($data[$i])?$data[$i]:0);
      }

oxygen commented 8 years ago

Currently I am forced to set_error_handler() to a handler which ignores errors, run PHPFontLib stuff, then restore_error_handler(). Not pretty.

set_error_handler(function($nSeverity, $strMessage, $strFilePath, $nLineNumber){
    if(
        $nSeverity!=E_NOTICE
        && strpos($strMessage, "Invalid argument supplied for foreach")===false
    )
    {
        throw new ErrorException($strMessage, /*nExceptionCode*/ 0, $nSeverity, $strFilePath, $nLineNumber);
    }
}, -1);

[...] FontLib calls

restore_error_handler();

PhenX commented 8 years ago

Do you have a sample font giving this warning ? I never had this problem.

pocketarc commented 8 years ago

See PR #37. If you run the HTML in the PR through dompdf, you'll get that error in php-font-lib.

oxygen commented 8 years ago

About half the fonts (or more) in GoogleFonts if I remember correctly.

PhenX commented 7 years ago

Fixed by 010c3e0e22a9ab0d9f93678692c80865f041e2d2