Grzegorz Grzegorz - 1 month ago 15
PHP Question

PHP if() does not return true nor calls all elements

I have following part of code:

if (($product->uploadable_files != $files_count || $product->text_fields != $text_count) && !count($this->errors) && !$product->update())
$this->errors[] = Tools::displayError('An error occurred while updating the custom configuration.');

How come (I'm completly lost atm) it does not call

At last one of those, should be called. And it is not.


This probably means it doesn't even reach that point. You can group the if-statement in three groups:

1st: $product->uploadable_files != $files_count || $product->text_fields != $text_count

2nd: !count($this->errors)

3rd: !$product->update()

If one of those groups is false, the entire condition will be false. And if 1st is false, it doesn't even reach 2nd and 3rd. And if 2nd is false, it doesn't reach 3rd.

Also, count never returns false. You're probably checking whether $this->errors is empty, so just use empty($this->errors).