Weedpacket
You don't get what I am saying here.
I am talking about the statement ...
if($value = safe_value($conn, $seardh)) {
The IF statement is a CONDITIONAL statement.
It requires a COMPARISON expression that evaluates to a boolean value.
A boolean has two and only two possible values. true or false.
A COMPARISON expression contains COMPARISON operators.
== Equal $x == $y Returns true if $x is equal to $y
=== Identical $x === $y Returns true if $x is equal to $y, and they are of the same type
!= Not equal $x != $y Returns true if $x is not equal to $y
<> Not equal $x <> $y Returns true if $x is not equal to $y
!== Not identical $x !== $y Returns true if $x is not equal to $y, or they are not of the same type
Greater than $x > $y Returns true if $x is greater than $y
< Less than $x < $y Returns true if $x is less than $y
= Greater than or equal to $x >= $y Returns true if $x is greater than or equal to $y
<= Less than or equal to $x <= $y Returns true if $x is less than or equal to $y
<=>
Note that the "=" operator IS NOT IN the COMPARISON operators list.
That's because it is an ASSIGNMENT operator
x = y x = y The left operand gets set to the value of the expression on the right
x += y x = x + y Addition
x -= y x = x - y Subtraction
x *= y x = x * y Multiplication
x /= y x = x / y Division
x %= y x = x % y Modulus
Note that the "=" operator IS IN the ASSIGNMENT operators list.
An ASSIGNMENT returns only ONE value if tested. That would be TRUE. As I demonstrated
in a previous post. An ASSIGNMENT does not return FALSE. It may return an error code
if the data types of the operands are incompatible in a heavily typed environment in which
case the program would abend. But an ASSIGNMENT doesn't return FALSE if the statement
is valid.
The code ...
if($value = safe_value($conn, $seardh)) {
is not a legitimate IF statement.
It doesn't matter what the safe_value() function does. It doesn't matter what the operands
are. It is an ASSIGNMENT expression. Not a COMPARISON expression which is the type of statement
the IF statement requires.
The safe_value() function or what it does is irrelevant. By the way, a function shouldn't be
returning different data types (string or boolean). It should only return one data type.