How to fix automatically generated PHP Cache file error (occurs when upgrading from PHP 7.4 to 8.x)

Dear PKP staffs and Forum members,

I am currently operating OPS3.3.0.8 (PHP7.4), but I plan to upgrade to PHP8.x soon.

Please tell me how to deal with PHP8 errors such as Deprecated errors and PHP Fatal errors (Uncaught TypeError, etc.) in PHP cache files created under the “./cache/t_compile/” directory.

ex.)

  • cfac7d723fa83a8468f3fec3577c93a53cdab919^4ef1996850f75e89a53007d1a8243f48d8f4148f_0.app.submissionformcategories…php

  • f09822d526ba2b77dee1b6fa34cba9dcc80abebc^756a7119cb48731a8fd45c250b45f4bcca2d6b01_0.app.frontendpagessearch.tpl.php

  • 00a0a0910209607cb33eb0fe6474f30ed7399ed7^589c85dd0397ef630218c8db230081934c6e247e_0.app.frontendcomponentssearchF.php

  • 2122dd4b4d038d06701b7a5cbc73d21546ea835d_0.app.formtextInput.tpl.php

I can fix the PHP cache file directly to temporarily deal with it, but when the cache file is regenerated, it will return to the original, so I would like to make a fundamental fix.

Best regards,
Minoru Tanabe.

Dear @bozana , @asmecher,
Since this matter is very urgent and important for me, I have nominated you.
Do you have any advice or comments on this matter?

Best,
Minoru Tanabe.

Dear Minoru

You can directly edit the source code, although this activity not recommended because will change the OJS/OPS source code that may lead to unexpected behavior in your OJS/OPS.

To be able to do this for example on this cache file :

  • 2122dd4b4d038d06701b7a5cbc73d21546ea835d_0.app.formtextInput.tpl.php

You can look the file to the folder :
lib/pkp/templates/form/textInput.tpl

If you have custom template you should find the appropriate file in your custom template folder since it will override the native file.

Regards
Hendra
OJT Team

Dear @navotera ,

Thank you for your advice.
I compared the cache file with the original template, but I don’t know how to fix the original template.
For example, if I want to add “(string)” to the parameter of the strstr function, I can add it to the cache file, but can I add it to the template file?

(strstr((string) $_smarty_tpl->tpl_vars[‘FBV_class’]->value,“datepicker”)

./cache/t_compile/2122dd4b4d038d06701b7a5cbc73d21546ea835d_0.app.formtextInput.tpl.php
(strstr((string) $_smarty_tpl->tpl_vars['FBV_class']->value,"datepicker") && $_smarty_tpl->tpl_vars['FBV_value']->value !== null) {

lib/pkp/templates/form/textInput.tpl
value="{if $FBV_multilingual}{$FBV_value[$formLocale]|escape}{elseif $FBV_class|strstr:"datepicker" && $FBV_value!==null}{$FBV_value|date_format:$dateFormatShort|escape}{else}{$FBV_value|escape}{/if}"

It would be helpful if you could tell me how to add to “$FBV_class|strstr:”.

Best regards,
Minoru Tanabe

Dear Minoru

Thank you for your reply.

The better way to do it to copy paste it on your theme folder, for example on the plugins/themes/default/ copy paste the lib/pkp/template/form folder and place the textInput.tpl file on that folder.

You can edit or modify whatever you want, then after you have finish you can clear cache of your OJS by following this guide.

By doing above steps, you are not modify the original OJS source code.

If you in case the page that use the file show “white / blank” it means you have some error to the coding modification and you need to enable display_error = on on your OJS config.

However, I still recommend to use PHP 7.4 since OJS => 3.3.0.13 actually does not support PHP 8.

Kind Regards
Hendra

Dear Hendra,

Thank you for your kind repley.
I understand how to test and debug it, but I’m not sure how to customize the Smarty template specifically.
Do you have any tips or advice on this?

In addition, please let me know the version of OJS/OPS that supports officially PHP 8.0 and PHP8.1.

Best regards,
Minoru Tanabe

Dear Minoru

The tips is using the child theme to override those tpl file from OJS/OPS.
On our experience the latest version of OJS/OPS does not fully compatible with PHP 8.

Based on our experience when handling hundred of client it is safe to say to use PHP 7.4 even on the latest version of OJS/OPS. You also need to take a consideration the ecosystem (plugins/third-party app) before decide to use PHP 8.

Regards
Hendra

Dear Hendra,

If possible, I would like to modify the php file and reflect it in the template instead of embedding the php code in the template file (.tpl). Is that possible?

Also, I heard earlier in this forum that OJS3.3/OPS3.3 is compatible with PHP8, but does that mean that it is not actually compatible?
Security support for PHP7.4 expires on November 28, 2022, so I need to complete PHP8 support by then.
So, I and my client are so pressed for time to upgrade to PHP8.

Best regards,
Minoru Tanabe

Hello Minoru

Yes it is possible to directly edit the file. I think the OJS will be support PHP8 on the later 3.3.0.14 version. On technical perspective it is better to wait for those version then upgrade your OJS. The expiration of security support does not mean that it has vulnerability right away on 22 Nov 2022.

However, you can try PHP 8 on your environment and let community know the issue here.

Good luck

Regards
Hendra

Dear Hendra,

Thank you for your repley.

I don’t really want to embed PHP code in Smarty template files.
So, I would like to modify the PHP file side.

For some reasons on our side, we will not be able to update the OPS version for a while.
So, we are forced to update to PHP8.x with the current version.

Anyway, I’ll do my best by trial and error.

Best regards,
Minoru Tanabe

Hi @Minoru_Tanabe!

The latest release of OPS should be compatible with PHP8.0 and we’re shortly going to add PHP8.1 compatibility (Back-port PHP8.1 compatibility to stable-3_3_0 · Issue #8193 · pkp/pkp-lib · GitHub). I suspect upgrading from your current release to the latest will make some if not all of these issues go away.

Meanwhile, I really don’t recommend editing the .tpl.php files directly; you can use the appropriate Smarty syntax instead and edit the .tpl file. For example, try the |default:"" modifier to add a default value to a possibly null variable. But I suspect this has already been fixed in the latest release; I would recommend upgrading, and if you still encounter problems, post the full error here and I’ll be able to make a more specific recommendation.

Regards,
Alec Smecher
Public Knowledge Project Team

2 Likes

Dear Alec Smecher,

Thank you for your useful reply.
As I mentioned earlier, we are in a situation where it is difficult to upgrade OPS immediately, so we decided to upgrade PHP only.
So far, I have already modified some source files and template files in the development environment, but I didn’t know what to do about cache files that caused Deprecated errors, so I made this post.
As you instructed, when it comes to modifying the template, I will use Smarty syntax and edit the .tpl file while referring to the fix on Github.

Thanks so much,
Best regards,
Minoru Tanabe

Hi @Minoru_Tanabe,

If you are able to include the full error message and stack trace to go with each problem, I may be able to identify specific changes in the git commit history that you can apply.

Regards,
Alec Smecher
Public Knowledge Project Team

1 Like

Hi @asmecher,

Thank you for your kind reply.
Some deprecated warning messages are also output in the sources under ./lib/pkp/lib/vendor/, but it seems that the modified sources for these are not posted on Github.

example.

PHP Deprecated: Function strftime() is deprecated in ./lib/pkp/lib/vendor/smarty/smarty/libs/plugins/modifier.date_format.php on line 81

PHP Deprecated: Function strftime() is deprecated in ./lib/pkp/lib/vendor/smarty/smarty/libs/plugins/function.html_select_date.php on line 312

PHP Deprecated: htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated in ./lib/pkp/lib/vendor/smarty/smarty/libs/plugins/modifier.escape.php on line 39

PHP Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /var/www/html/ops/lib/pkp/lib/vendor/ezyang/htmlpurifier/library/HTMLPurifier/Lexer.php on line 312

I made a temporary fix here, but it would be helpful if you could let me know how to fix it officially.

Regards,
Minoru Tanabe

Hi @Minoru_Tanabe,

We already have fixes for these merged into stable-3_3_0 for release in 3.3.0-14. This is done by using the GitHub - cweagans/composer-patches: Simple patches plugin for Composer composer module, which allows for applying patches to installed Composer dependencies.

See e.g. the patches in this PR:

(I wouldn’t normally choose to patch 3rd party dependencies, but it’s necessary in order to support both PHP8.1 and our baseline PHP7.3; there is no set of official dependencies that will support both of these intercompatibly.)

Regards,
Alec Smecher
Public Knowledge Project Team

1 Like

Hi @asmecher,

Thank you for your useful information.
However, we have made many customizations to OPS and have completed support for PHP8.1, so we are unable to override the new OPS version files.
I think it’s a very bad situation, but we have no choice but to operate as it is for the time being.
I would like to improve this situation at some point.

Best regards,
Minoru Tanabe
Jxiv Developer Team