Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+3 votes
990 views
in Q2A Core by
https://prnt.sc/6m9MXX5ldJpR

I am getting this error. My php version is 8
Q2A version: 1.8.6

1 Answer

+1 vote
by

Hello rupu123,

The easiest solution is updating to Question2Answer v1.8.8 (or above) which significantly improves support for PHP 8. Here's a quick explanation of what caused the problem and how to fix it.

PHP 8.1 arrival

Some internal functions, such as strlen(), no longer allow null arguments. Here is a quick comparison:

Before PHP 8.1:

echo strlen(null); // No deprecation notice is shown up.
// -> 0

As of PHP 8.1:

echo strlen(null); // Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in ... on line ...
// -> 0

Please note that even though a deprecation notice is thrown, it still returns the correct value (0 in this case). It means it continues working as usual for now (until PHP 9 is released, then it will stop working completely).

Solution

The RFC describing this issue is really helpful for possible resolutions and I highly recommend reviewing it. As of Question2Answer, the official resolution was to make use of the Null Coalescing Operator (??) when possible; here is an example from GitHub, which replaces:

if (strlen($error )) {...}

with this:

if (strlen($error ?? '')) {...}

This effectively fixes the issue.

Tidbits

  • RFC stands for Request For Comments, a document used by the Internet community to define new standards and share technical information [1]. PHP community makes use of RFCs to propose updates and improvements to the PHP language. They are approved (or rejected) and implemented in the language itself.
  • The Null Coalescing Operator (??) was introduced with PHP 7. It provides a shorthand for checking if a variable is set before using it. For example, $x ?? $y; is equivalent to isset($x) ? $x : $y;. [2, 3]

Here is another PHP 8 related answer with further explanation on other similar problems:


Thanks for going through this answer! Feel free to ask any follow-up questions in the comments below. Backhand index pointing down emoji

Have a nice day!

...