Contact Us form PHP warnings

Using PHP 8.3 (or 8.1), CS-Cart v 4.20
When submitting the Contact Us form.
Bug Tracker reports these four warnings:

PHP Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in app/addons/product_variations/src/HookHandlers/SeoHookHandler.php on line 54

PHP Deprecated: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in app/functions/fn.common.php on line 4019

PHP Deprecated: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in app/functions/fn.common.php on line 3999

PHP Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in app/functions/fn.common.php on line 3912

I don’t know why the addon for product variations would even be included here, but it is. I don’t even use product variations.

Hello

This isn’t a bug in the store, but rather a warning about code incompatibility with PHP 8.
PHP 7 accepted this without a word, but PHP 8.1 and later reports it as “deprecated.”
The form works correctly, and emails are sent. It can be silenced with a single line in the installation configuration.

Have a nice day

Best regards
Robert

I’m aware. PHP 8.1 and any older version is obsolete. PHP 8.3 has been supported since v4.19. But the cart has a few instances of deprecated code and the built in bug tracker will show you them all.
What line do you propose to be edited to silence them? I’m not doing a new installation as I’ve run CS-Cart for 16 years.

Hello

The fix goes into file config.local.php

Add this single line to config.local.php add somewhere at the top

error_reporting(E_ALL & ~E_DEPRECATED);

That filters out the deprecation notices.

Have a nice day

Best regards
Robert

I’ve been doing that for years. Deprecated warnings still get reported in debug mode (unless you disable it local_config.php), and they still write to my PHP error log.
I don’t recall in which script CS-Cart includes a function that writes the warnings to the PHP error log regardless of PHP error reporting configuration or config.local settings, but my error log gets about 50k of warnings a day for these deprecated functions (and I don’t even have high traffic):
PHP Deprecated: strip_tags()
PHP Deprecated: html_entity_decode()
PHP Deprecated: strpos()
PHP Deprecated: preg_match()

I fail to see why CS-Cart didn’t search all their code for these functions and update everywhere they are used in the last release.

Thank you for informing us about this issue.

I have forwarded it to our development team to fix in future CS-Cart versions.

1 Like

Hello, @magpiedon !

Thank you for your report. The deprecations have been fixed and the fix will be included in the next patch release after 4.22.1.

In the meantime, you can apply the following patch:

You can read about how to apply the patch in our documentation: https://docs.cs-cart…_diff_file.html

Thank you DanielB! That did the trick.