Fatal error: Switch statements may only contain one default clause in mpdf.php

自闭症网瘾萝莉.ら 提交于 2019-12-07 15:20:44

问题


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



来源:https://stackoverflow.com/questions/47188651/fatal-error-switch-statements-may-only-contain-one-default-clause-in-mpdf-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!