After update to 3.5 and changing PHP to 8.1 the following error code occurs when form is submitted:
Warning: Trying to access array offset on value of type null in .../includes/classes/fieldstypes/fieldtype_php_code.php(175) : eval()'d code on line 6
Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in .../includes/classes/fieldstypes/fieldtype_php_code.php(175) : eval()'d code on line 7
Warning: Cannot modify header information - headers already sent by (output started at .../includes/classes/fieldstypes/fieldtype_php_code.php(175) : eval()'d code:6) in .../includes/functions/urls.php on line 26
PHP warning and error page
- support
- Site Admin
- Posts: 6231
- Joined: 19 Oct 2014, 18:22
- Name: Sergey Kharchishin
- Location: Russia, Evpatoriya
Re: PHP warning and error page
You have to update your php code. PHP 8.1 not support null value to strlen function.
Re: PHP warning and error page
This was my PHP code. Can you suggest strlen alternative?
//
$status = [157];
$case_id = [id];
//$output_value = $case_id;
$ts_query = db_query("SELECT app_comments.date_added AS ts FROM app_comments INNER JOIN app_comments_history ON app_comments_history.comments_id=app_comments.id WHERE app_comments_history.fields_value=43 AND app_comments.items_id= '" . $case_id ."'");
$ts_info = db_fetch_array($ts_query);
$ts = $ts_info['ts'];
if(strlen($ts) > 0){
$output_value = date('d/m/Y H:i',$ts);
}else{
$output_value = "";
}
//
$status = [157];
$case_id = [id];
//$output_value = $case_id;
$ts_query = db_query("SELECT app_comments.date_added AS ts FROM app_comments INNER JOIN app_comments_history ON app_comments_history.comments_id=app_comments.id WHERE app_comments_history.fields_value=43 AND app_comments.items_id= '" . $case_id ."'");
$ts_info = db_fetch_array($ts_query);
$ts = $ts_info['ts'];
if(strlen($ts) > 0){
$output_value = date('d/m/Y H:i',$ts);
}else{
$output_value = "";
}
-
- Posts: 174
- Joined: 23 Feb 2021, 16:31
- Name: Edi Supriyadi
- Location: BDG Indonesia
Re: PHP warning and error page
You have to consider the possibility of empty result of your query. Because if it is, it will give null value to $ts which caused the warning.
Try changing your code like this:
Try changing your code like this:
Code: Select all
$status = [157];
$case_id = [id];
//$output_value = $case_id;
$ts_query = db_query("SELECT app_comments.date_added AS ts FROM app_comments INNER JOIN app_comments_history ON app_comments_history.comments_id=app_comments.id WHERE app_comments_history.fields_value=43 AND app_comments.items_id= '" . $case_id ."'");
if(db_num_rows($ts_query))
{
$ts_info = db_fetch_array($ts_query);
$ts = $ts_info['ts'];
if(strlen($ts) > 0){
$output_value = date('d/m/Y H:i',$ts);
}else{
$output_value = "";
}
}
Re: PHP warning and error page
My code was working fine with PHP 7.4 but as strlen() got deprecated in PHP 8.1, so I need a workaround to replace strlen()eddydeniro wrote: ↑03 Feb 2024, 19:25 You have to consider the possibility of empty result of your query. Because if it is, it will give null value to $ts which caused the warning.
Try changing your code like this:
Code: Select all
$status = [157]; $case_id = [id]; //$output_value = $case_id; $ts_query = db_query("SELECT app_comments.date_added AS ts FROM app_comments INNER JOIN app_comments_history ON app_comments_history.comments_id=app_comments.id WHERE app_comments_history.fields_value=43 AND app_comments.items_id= '" . $case_id ."'"); if(db_num_rows($ts_query)) { $ts_info = db_fetch_array($ts_query); $ts = $ts_info['ts']; if(strlen($ts) > 0){ $output_value = date('d/m/Y H:i',$ts); }else{ $output_value = ""; } }
Can you please help?
- support
- Site Admin
- Posts: 6231
- Joined: 19 Oct 2014, 18:22
- Name: Sergey Kharchishin
- Location: Russia, Evpatoriya
Re: PHP warning and error page
You have to check if $ts_info exist before strlen
Re: PHP warning and error page
Thanks @Sergey and @Edi. It's working