Thread Rating:
  • 4 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get simple 3.3.16 support for php 8.0
#16
Migrating my website CMS to PHP 8.1 which is now the current version.

I found two deprecations which affect GetSimple (will probably become hard errors when PHP9 comes):

1. They changed null parameter handling in built-in string functions like trim(), substr(), htmlentities() etc.
Until PHP 8.0, these functions silently handled a null argument as an empty string. Starting with PHP 8.1, a warning is thrown that passing null parameter is deprecated.
There are a few places in GetSimple cms, and unfortunately also in i18N plugings.
It is easy to fix this change by adding a null coalescing operator and an empty string (parameter ?? "") in any place where the warning pops up.

Fixes in GetSimple core:

/admin/inc/basic.php: line 85:
  $text = mb_convert_encoding($text ?? "",'HTML-ENTITIES',$from_enc);

/admin/inc/cookie_functions..php: line 23:
  return setcookie($id, $value, $expire, $cookie_path, $cookie_domain ??"", $cookie_secure??"", $cookie_httponly);

/admin/inc/cookie_functions..php: line 35:
return setcookie($id,false,1,$cookie_path,$cookie_domain??"",$cookie_secure??"", $cookie_httponly);

Also fixed some warnings of the same type in i18N Bases and i18N Search, but I do not know what Mvlcek thinks about modifying his plugins.

2. FILTER_SANITIZE_STRING is deprecated and must be removed.
It is used in admin/inc/security_functions.php in function var_out($var, $filter = "special").

I changed this function like this:

PHP Code:
function var_out($var,$filter "special"){
 
$var = (string)$var;

 
// php 5.2 shim
 
if(!defined('FILTER_SANITIZE_FULL_SPECIAL_CHARS')){
 
define('FILTER_SANITIZE_FULL_SPECIAL_CHARS',522);
 if(
$filter == "full") return htmlspecialchars($varENT_QUOTES);
 }

 
// php 8.1: FILTER_SANITIZE_STRING deprecated
 
if(function_exists"filter_var") && ($filter !== "string" )){
 
$aryFilter = array(
 
"int"    => FILTER_SANITIZE_NUMBER_INT,
 
"float"  => FILTER_SANITIZE_NUMBER_FLOAT,
 
"url"    => FILTER_SANITIZE_URL,
 
"email"  => FILTER_SANITIZE_EMAIL,
 
"special" => FILTER_SANITIZE_SPECIAL_CHARS,
 
"full"    => FILTER_SANITIZE_FULL_SPECIAL_CHARS
 
);
 if(isset(
$aryFilter[$filter])) return filter_var$var$aryFilter[$filter]);
 return 
filter_var$varFILTER_SANITIZE_SPECIAL_CHARS);
 }
 else if (
$filter === "string") {
 return 
htmlspecialchars($var);
 }
 else {
 return 
htmlentities($var);
 }


With these additional fixes, my GetSimple site seems to run flawlessly and without warnings on PHP 8.1. However, there are probably parts of the CMS I currently did not use, which also would throw such warnings.

Hope this helps a little further in making GetSimple "future-proof" Wink
Reply


Messages In This Thread
RE: Get simple 3.3.16 support for php 8.0 - by Knobbles - 2022-09-29, 04:52:35



Users browsing this thread: 1 Guest(s)