Skip to content

Commit

Permalink
Pass correctly typed arguments to internal functions
Browse files Browse the repository at this point in the history
PHP 8.1 deprecated implicit conversions of float to int and passing null to non-nullable parameters:

https://php.watch/versions/8.1/deprecate-implicit-conversion-incompatible-float-string
https://php.watch/versions/8.1/internal-func-non-nullable-null-deprecation

Co-authored-by: Jan Tojnar <[email protected]>
  • Loading branch information
Björn Lindh and jtojnar committed Jan 6, 2022
1 parent 9814e76 commit 7825371
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions base.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ function sync($key) {
**/
private function cut($key) {
return preg_split('/\[\h*[\'"]?(.+?)[\'"]?\h*\]|(->)|\./',
$key,NULL,PREG_SPLIT_NO_EMPTY|PREG_SPLIT_DELIM_CAPTURE);
$key,-1,PREG_SPLIT_NO_EMPTY|PREG_SPLIT_DELIM_CAPTURE);
}

/**
Expand Down Expand Up @@ -389,18 +389,18 @@ function set($key,$val,$ttl=0) {
if (version_compare(PHP_VERSION, '7.3.0') >= 0) {
unset($jar['expire']);
if (isset($_COOKIE[$parts[1]]))
setcookie($parts[1],NULL,['expires'=>0]+$jar);
setcookie($parts[1],'',['expires'=>0]+$jar);
if ($ttl)
$jar['expires']=$time+$ttl;
setcookie($parts[1],$val,$jar);
setcookie($parts[1],$val?:'',$jar);
} else {
unset($jar['samesite']);
if (isset($_COOKIE[$parts[1]]))
call_user_func_array('setcookie',
array_merge([$parts[1],NULL],['expire'=>0]+$jar));
array_merge([$parts[1],''],['expire'=>0]+$jar));
if ($ttl)
$jar['expire']=$time+$ttl;
call_user_func_array('setcookie',[$parts[1],$val]+$jar);
call_user_func_array('setcookie',[$parts[1],$val?:'']+$jar);
}
$_COOKIE[$parts[1]]=$val;
return $val;
Expand Down Expand Up @@ -501,11 +501,11 @@ function clear($key) {
if (version_compare(PHP_VERSION, '7.3.0') >= 0) {
$jar['expires']=$jar['expire'];
unset($jar['expire']);
setcookie($parts[1],NULL,$jar);
setcookie($parts[1],'',$jar);
} else {
unset($jar['samesite']);
call_user_func_array('setcookie',
array_merge([$parts[1],NULL],$jar));
array_merge([$parts[1],''],$jar));
}
unset($_COOKIE[$parts[1]]);
}
Expand Down Expand Up @@ -713,7 +713,7 @@ function fixslashes($str) {
**/
function split($str,$noempty=TRUE) {
return array_map('trim',
preg_split('/[,;|]/',$str,0,$noempty?PREG_SPLIT_NO_EMPTY:0));
preg_split('/[,;|]/',$str?:'',0,$noempty?PREG_SPLIT_NO_EMPTY:0));
}

/**
Expand Down Expand Up @@ -1225,7 +1225,7 @@ function expire($secs=0) {
$time=microtime(TRUE);
header_remove('Pragma');
header('Cache-Control: max-age='.$secs);
header('Expires: '.gmdate('r',$time+$secs));
header('Expires: '.gmdate('r',round($time+$secs)));
header('Last-Modified: '.gmdate('r'));
}
else {
Expand Down

0 comments on commit 7825371

Please sign in to comment.