webERP Forum

Full Version: PHP 8.0 Fatal error: tcpdf, barcodepack and PHPExcel use curly braces
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hi all, I was trying to learn how to format a cheque for printing, but may have stumbled a PHP 8.0 bug in the process.


Quote:[Tue Jan 17 15:17:55.595588 2023] [php:error] [pid 2413] [client 162.223.103.50:9089] PHP Fatal error:  Array and string offset access syntax with curly braces is no longer supported in /usr/local/www/weberp/includes/tcpdf/tcpdf.php on line 17018, referer: https://weberp.dalescott.net/AgedSuppliers.php


I was trying to run an Aged Supplier Report [Menu > Payables > Inquiries and Reports > Aged Supplier Report] to see if I had any suppliers with an outstanding balance I could write a cheque to. I accepted the defaults in the Aged Supplier Analysis form AgedSuppliers.php (from 1, to zzzzzz, All suppliers with balances, US Dollars, Summary Report), and then clicking Print PDF resulted in a HTTPD ERROR 500.

Attempting the following (which also generate PDFs) resulted in a HTTPD ERROR 500 as well:

  • Payment Run Report
  • Supplier Balances At A Prior Month End

Does it seem reasonable I've stumbled across a PHP 8 bug? Is there anything I can do to help troubleshoot further?

The server stack is:

  • Apache 2.4.54
  • PHP 8.0.26
  • MariaDb 10.5.18

Cheers,
Dale
Thanks Dale. I'm about to head bed now (NY tz), but I did find this deprecation info about the curly braces: https://wiki.php.net/rfc/deprecate_curly...ray_access

Let me know if you may still be fighting this later today, and I'll see if I can squeeze in a little weekday time to take a look.

I also know that the tcpdf may be based on older php version too, though not sure of the target version for the tcpdf.
No worries Paul, I can do testing and investigation but will likely need more direction to actually update code.

I ran the check_syntax.sh script on my server (PHP 8.0), happily the only error reported was the curly brace issue and all the files appear to be in 3rd-party libraries. I will investigate the libraries further and report (current versions, PHP version compatibility, and backwards compatibility with the versions we're using). Does this seem the best course of action?

./includes/barcodepack/class.s2of5.php
./includes/barcodepack/class.upc.php
./includes/barcodepack/class.qrCode.php
./includes/barcodepack/class.linearBarcode.php
./includes/barcodepack/class.code128.php
./includes/barcodepack/class.i2of5.php
./includes/barcodepack/class.ean13.php

./includes/tcpdf/include/tcpdf_images.php
./includes/tcpdf/include/tcpdf_filters.php
./includes/tcpdf/tcpdf.php

./Classes/PHPExcel/ReferenceHelper.php
./Classes/PHPExcel/Writer/Excel5/Workbook.php
./Classes/PHPExcel/Writer/Excel5/Worksheet.php
./Classes/PHPExcel/Writer/Excel5/Parser.php
./Classes/PHPExcel/Cell/DefaultValueBinder.php
./Classes/PHPExcel/Calculation.php
./Classes/PHPExcel/Worksheet/AutoFilter.php
./Classes/PHPExcel/Cell.php
./Classes/PHPExcel/Shared/OLE.php
./Classes/PHPExcel/Shared/ZipStreamWrapper.php
./Classes/PHPExcel/Shared/String.php
./Classes/PHPExcel/Reader/Excel5/Escher.php
./Classes/PHPExcel/Reader/SYLK.php
./Classes/PHPExcel/Reader/Excel2003XML.php
./Classes/PHPExcel/Reader/Excel5.php
./Classes/PHPExcel/Calculation/FormulaParser.php
./Classes/PHPExcel/Calculation/Engineering.php
./Classes/PHPExcel/Calculation/Functions.php
./Classes/PHPExcel/Calculation/TextData.php
So far, so good. I don't want to get my hopes up, but I replaced tcpdf-5.9.161 with tcpdf-6.2.2 and now the "Aged Supplier Report", "Payment Run Report" and "Supplier Balances At A Prior Month End" report generate PDFs without error. A "Purchases from Suppliers" reports doesn't seem to use suitable margins, but I expect this to be a webERP page formatting issue, and not a tcpdf issue per se (but what do I know ;-)). See https://i.imgur.com/F89hyqS.png

I will look at barcodepack and PHPExcel next, but how do you want to proceed with tcpdf? I can follow the dev workflow in the Github wiki, create a local feature branch to replace tcpdf-5.8.161 with tcpdf-6-2.2, and send a pull request which will allow others to test more comprehensively than I can (I will include only the same directories, fonts, and files that were included from 5.9.161, and will keep the custom font files javiergb.php and javiergp.php). Should I proceed with this?  Is there anything else I need to do?

P.S. I don't understand the purpose of tcpdf_config_alt.pdf. It's not included in tcpdf-6.2.2. Do you know if this is an alternate config created by the webERP project? Does it need to be carried forward?
barcodepack is not quite as promising, the barcodepack.com web site domain has been abandoned, and the last update on Sourceforge in 2013 (https://sourceforge.net/projects/barcodepack/) still has curly braces. Does anyone know if barcodepack is still going?

However, I'm thinking simply replacing the curly braces with square brackets might be feasable.

Here is an example of curly braces syntax caught by check_syntax.sh in file class.linearBarcode.php ("$text{$i}" in line 4):

PHP Code:
protected function checkAllowedChars($text$allowedChars)
{
    for($i=0$i<strlen($text); $i++) {
        if(!in_array($text{$i}, $allowedChars)) {
            throw new Exception('Input text contains nonallowed characters.'E_BAD_CHARS);
            return false;
        }
    }
    return true;


I haven't worked with barcodes before, and have no way to test. Does the code look like a simple substitution will be possible?

If simple substitution will work here, and if the rest of the issues are of similar complexity, then I'll go ahead and change them all. 

When all is done, I'll create a new feature branch and send a pull request for testing.
PHPExcel also appears to have been abandoned (https://github.com/PHPOffice/PHPExcel/), the archived version in GitHub is newer than that in webERP, but still uses curly braces. Is anyone aware of PHPExcel continuing somewhere else?

This is an offending curly braces snippet from Classes/PHPExcel/Writer/Excel5/worksheet.php, the cooresponding section in the file in the GitHub archive (last commit Sept 2016) is identical.

PHP Code:
// Strip the '=' or '@' sign at the beginning of the formula string
if ($formula{0} == '=') {
    $formula substr($formula1);
} else {
    // Error handling
    $this->writeString($row$col'Unrecognised character for formula');
    return -1;


Does this look like simple substitution will work here? If so, and if the if the remainder of the curly braces are of similar complexity, then I'll go ahead and change them all but will need help testing.

When all is done, I'll create a new feature branch and send a pull request for testing.
Apologies for the delayed response, Dale, but yes, replacing the {} to [] should do it for all places to quell the new fatal error.

I'll give the branch a test run too, but I need to update to 8 myself, I'm still on 7.4 at the moment.
Thanks. I'm working on it, you should have the pull requests by this weekend.
Sure, no rush or worries, as you get time, like me. Smile
Hi Paul, I submitted a pull request for upgrading tcpdf to v6.6.2. It should be compatible with PHP 5+ (not PHP 4).

This was my first pull request to any project, so it was a learning experience. Let me know if there was anything I could have done differently or if there are any issues.

It will take me a few days for the barcodepack and PHPExcell pull requests, but I should also wait to see how this one works first anyway. There is absolutely no hurry though.

Cheers,
Dale
Pages: 1 2