Fatal error: Switch statements may only contain on

2020-06-23 09:25发布

问题:

I am using mPDF and it is working fine with localhost. I upload the project to live server and it is not generating pdf correctly.

<?php

// HTML ommited

$body = ob_get_clean();

include ("mpdf/mpdf.php");

$mpdf = new mPDF('+aCJK', 'A4', '', '', 0, 0, 0, 0, 0, 0);

$mpdf->WriteHTML($body);

$mpdf->Output('SaveToPDF.pdf', 'D');

On the top, I put the error show code. To see the error what is going wrong I have the following error.

Fatal error: Switch statements may only contain one default clause in /customers/d/e/a/....URL..GO..HERE/mpdf.php on line 1432

I am using PHP Version 5.6.31 on my Localhost and on live I am using one.com and there I can switch to different PHP versions, and I tried all. i.e. 5.6, 7.0, 7.1, 7.2 beta

I am using mPDF 5.7 and it is not composer version. I wanted to use chines character for my pdf and it good support available in 5.7. That's why I chose older version

回答1:

Old mpdf versions don't support PHP7, unfortunately (mpdf issue). You can either:

  1. Switch to actual mpdf version and use this workaround for chinese fonts;
  2. Or change your live server PHP to 5.6 (PHP RFC multiple default cases syntax error);
  3. Or fix this switch issue in mpdf source yourself (people discussed the possible solution in this hhvm issue), you just need to remove one of the default statements.


回答2:

Older post but this may help someone, I had the same issue moving a site from PHP 5.6 to PHP 7, I have found an updated version of MPDF which works fine for me at https://github.com/kbs1/mpdf-5.7-php7



标签: php mpdf