PHP 8.1

PHP 8.1 so....

PHP 8.1 is released, so the primary question is: when will PHsPeed support that? Well, the answer is quite simple, very soon! Xampp released their web server with PHP 8.1 a few days ago, and in our development center, we already have implemented PHP 8.1. Nothing serious so far and quickly fixable, but it proves that we have to test all our runtime modules. With PHsPeed version 2 being released on the 23rd of December, there is no time to test all thorough. Therefore PHP 8.1 will not be released in the upcoming main release, especially since we did find compatibility issues in our runtime. But expect PHP 8.1 to be released in the 3rd week of January of 2022.

So what are the incompatibilities? Do you have to change your event code, if you have any? That is a tricky question to answer because it depends. You can find the most critical issues here.

So far, there is one issue of this list that applies to our runtime, and that is:

Passing null to non-nullable parameters of built-in functions

Scalar types for built-in functions are nullable by default. This behavior is deprecated to align with the behavior of user-defined functions, where scalar types need to be marked as nullable explicitly.

var_dump(str_contains("foobar", null));
// Deprecated: Passing null to parameter #2 ($needle) of type string
//             is deprecated

If you use the rtrGetVar function to retrieve some value from your $_Get or $_Post string, this situation can occur if the variable does not exist, then it will by default return a NULL value.

So something like this will not work any more, if 'myvar' is not always present:

if(rtrGetVar('myvar')=='abc') { ... }

To fix this issue we have added a new $default parameter

if(rtrGetVar('myvar', false, '')=='abc') { ... }

The second parameter allows you to load the data 'raw' without processing (but use with care as it is a potential security leak if you use this). This could be omitted as it is defaulted to false but mandatory if you use the default value. So both syntaxes are correct, but if you are not sure about the value of the variable, you need to test this before use. Otherwise, you will get a deprecated error message.

There are more situations than this one. All compare functions will fail if they have a NULL value, the same goes for NULL instead of an empty array. You must scan your code to see if this situation can occur.

So in short, if you want to use PHP 8.1, you need to test your software for issues, as the above is a very common situation. So are we. But if you find any issue in our runtime, then please report and we will fix this immediately. Did you know that the average time to fix an issue is days? You can find all bug info in our bug tracker. No hidden secrets wink

Happy coding and let's simplify!

18 Dec 2021 Blog None