Weedpacket
I'm talking about logic.
If the code is performing an assignment when it should be performing a comparison
then the outcome may well be unpredictable.
This is clearly questionable and therefore warrants attention.
if($value = safe_value($conn, $seardh)){
Because the next step in the process depends on the outcome of that statement ie: true or false.
A statement of the nature
if ($x = 88){
echo "true";
} else {
echo "false";
}
is ALWAYS going to evaluate TRUE and therefore the code in the first curly brackets in this case
foreach(['title', 'company', 'category', 'description', 'time'] as $column) {
$wheres[] = "`$column` LIKE '%$value%'";
}
is always going to be executed whether it's logically appropriate or not.
A statement of the nature
if ($x == 88){
echo "true";
} else {
echo "false";
}
will evaluate TRUE OR FALSE depending on whether $x has a value 88 and therefore the code in the
first curly brackets in this case
foreach(['title', 'company', 'category', 'description', 'time'] as $column) {
$wheres[] = "`$column` LIKE '%$value%'";
}
may be executed or it may not depending on the value of $x.
The fact that this block of code is encapsulated within an IF statement suggests that it should only
be executed conditionally.
If this code needs to be executed UNCONDITIONALLY then there's actually no logical reason in having
it subject to an IF condition at all.