Page 1 of 1

error_message does not work with php 8.1

Posted: 2022-07-16 19:31
by AhmedBR
I am using the following formula in before update:

Code: Select all

$chkCer=sqlvalue("select status from freight where `id` = {$data['freight']}",$eo);
if ( $chkCer =='Canceled'){$args['error_message'] = 'Alert: Canceled!';return FALSE;};
Works perfectly on 7.4, but does nothing in 8.1, as if the formula is not there.
Any idea what I should change in the formula to make it work in 8.1?

The funny part is I have other formulas almost same as this one (just different message), work on both.
I am just having hard time with this particular one, cannot see why it is not working!
Changing php from 8.1 to 7.4 it works, if I change back it stops!

thanks

Re: error_message does not work with php 8.1

Posted: 2022-07-16 19:49
by jsetzer
Capital letter "v" in sqlValue(...) missing

Re: error_message does not work with php 8.1

Posted: 2022-07-16 20:22
by AhmedBR
thanks for the reply, tried V, but that did not work, and the others are the same, with small v.

Re: error_message does not work with php 8.1

Posted: 2022-07-17 00:49
by jsetzer
You are right, I have just learned something new: function names are not case-sensitive in PHP.
Case sensitive

variables, constants, array keys, class properties, class constants

Case insensitive

functions, class constructors, class methods, keywords and constructs (if, else, null, foreach, echo etc.)

Re: error_message does not work with php 8.1

Posted: 2022-07-17 00:55
by jsetzer
Other Ideas:
  • Can you please check value of $chkCer and $args by var-dumping before return
  • We cannot see your function. Are you passing $args by reference?
    Can you please show the whole function TABLENAME_before_update

Re: error_message does not work with php 8.1

Posted: 2022-07-17 12:31
by AhmedBR
It is working now!
I have no idea what happened since I did not change a single letter.

Maybe 8.1.8 solved the problem, whatever that was (server PHP updated from 8.1)

that was the full function, nothing else is there actually:

<code>
function toll_before_update(&$data, $memberInfo, &$args) {
$chkCer=sqlvalue("select status from freight where `id` = {$data['freight']}",$eo);
if ( $chkCer =='Canceled'){$args['error_message'] = 'Alert: Canceled!';return FALSE;};

return TRUE;
}
</code>

Anyway, what I learned from this: if I have a formula that worked fine and just stopped for no reason check your PHP version before and after!
That my rule number one now.

Thanks JAN and have a nice day