mpdf / mpdf

PHP library generating PDF files from UTF-8 encoded HTML
https://mpdf.github.io
GNU General Public License v2.0
4.37k stars 1.06k forks source link

Array and string offset access syntax with curly braces is deprecated while using {PAGENO} #1496

Closed neerajrajendran closed 3 years ago

neerajrajendran commented 3 years ago

I found this bug

While using {PAGENO} and {nb} , I am getting this error "Array and string offset access syntax with curly braces is deprecated"

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

mPDF = 8.0^ PHP version = 7.4.22 server = linux

This is the PHP code snippet I use

<?php

$mpdf->SetHTMLFooter('<div class="footer"> page: {PAGENO}/{nb}</div>');

How do I solve this without changing the PHP version.

Thank you

finwe commented 3 years ago

Unable to reproduce. Provide example code that actually reproduces this issue.

finwe commented 3 years ago

Make sure your mPDF version is >= v8.0.4, PHP 7.4 is not supported before that.

neerajrajendran commented 3 years ago

Is there any alternate way of putting page number on SetHTMLFooter method, instead of using {PAGENO}

finwe commented 3 years ago

If you found an notice/warning/error in mPDF, help reproduce it and fix it. If you have a general question/troubleshooting, adhere to contribution guidelines.

neerajrajendran commented 3 years ago

my mPDF version is 8.0.11 still its not working!

finwe commented 3 years ago

Unable to reproduce. Provide example code that actually reproduces this issue.

neerajrajendran commented 3 years ago
<?php

require_once __DIR__ . '/vendor/autoload.php';

$mpdf = new \Mpdf\Mpdf();

$mpdf->SetHTMLFooter('<div class="footer"> page: {PAGENO}/{nb}</div>');

$mpdf->WriteHTML('<h1 class="header">Page Title</h1>');

$mpdf->Output();
finwe commented 3 years ago

No, still works correctly.

neerajrajendran commented 3 years ago

This doesn't works with php 7.4.22. other versions this works fine.

finwe commented 3 years ago

No, I just generated the PDF with your code with PHP 7.4.22. Repeating "doesn't works" is not helpful, provide more information. You can start with the stack trace of the error.

mtangoo commented 2 years ago

https://www.php.net/manual/en/migration74.deprecated.php#migration74.deprecated.core.array-string-access-curly-brace

I think it is dropped in some upper version or something. Today I hit this snag and couldn't believe to find this:

$this->bodyBackgroundColor{0} == 5

Never knew even that it was part of the language

mtangoo commented 2 years ago

I Fixed the error until it generated the PDF. do not have time to sort things and make PR. Whoever can ATM, here is the zip of src MPDF-src.zip

rafasashi commented 2 years ago

since PHP 7.4 curly braces method for accessing array elements has been deprecated, so change the bellow syntax :

$this->bodyBackgroundColor{0}

into to this:

$this->bodyBackgroundColor[0]

https://wiki.php.net/rfc/deprecate_curly_braces_array_access

lagraviereScience commented 1 year ago

The problem is simple: PHP 8.0 and further do not accept curly braces to access array and strings: it's been deprecated.

So, either switch a former version of PHP Or, search and replace all arrays and strings accessed with curly braces