Skip to content

Commit

Permalink
Fix fatal (PHP8.X) type issue with abs, and amend dol_eval return type
Browse files Browse the repository at this point in the history
# Fix fatal (PHP8.X) type issue with abs, and amend dol_eval return type

I got the following message:
`Fatal error: Uncaught TypeError: abs(): Argument #1 ($num) must be of type int|float, string given in D:\mdeweerd\workspace\dolibarr\htdocs\projet\list.php on line 233`

I examined the phan report and there was no mention of this because dol_eval was
said to return mixed.

In order to detect such cases, I amended the dol_eval return type to ensure to find
most of the locations where a cast is needed.
  • Loading branch information
mdeweerd committed Apr 2, 2024
1 parent 7d49bea commit e64e577
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion htdocs/core/lib/functions.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -9925,7 +9925,7 @@ function verifCond($strToEvaluate, $onlysimplestring = '1')
* @param string $onlysimplestring '0' (deprecated, do not use it anymore)=Accept all chars,
* '1' (most common use)=Accept only simple string with char 'a-z0-9\s^$_+-.*>&|=!?():"\',/@';',
* '2' (used for example for the compute property of extrafields)=Accept also '[]'
* @return mixed Nothing or return result of eval
* @return void|string Nothing or return result of eval (even if type can be int, it is safer to assume string and find all potential typing issues as abs(dol_eval(...)).
* @see verifCond()
* @phan-suppress PhanPluginUnsafeEval
*/
Expand Down
2 changes: 1 addition & 1 deletion htdocs/projet/list.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@
foreach ($object->fields as $key => $val) {
// If $val['visible']==0, then we never show the field
if (!empty($val['visible'])) {
$visible = dol_eval($val['visible'], 1, 1, '1');
$visible = (int) dol_eval($val['visible'], 1, 1, '1');
$arrayfields['p.'.$key] = array(
'label' => $val['label'],
'checked' => (($visible < 0) ? 0 : 1),
Expand Down

0 comments on commit e64e577

Please sign in to comment.