cakephp/cakephp

Strpos result comparison

yannouche34490 opened this issue · 3 comments

if (strpos($name, ' ') < 1) {

Description

Hello,

when you make comparison between strpos result and 1, PHP will cast the result to a int even if function returns false. It can result an unexpected true comparison.

Best regards.

CakePHP Version

4.4.0

PHP Version

8.2

Is it actually a Bug? From what I understand this is intentional here

The check is to throw an exception if a space is found at the first position (strpos will return 0) or if the name does not have a space (strpos will return false) and it works as intended.

The check is to throw an exception if a space is found at the first position (strpos will return 0) or if the name does not have a space (strpos will return false) and it works as intended.

Oh by mad, I didn't think things like that.