Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Str::includes return unexpected result #14301

ZhangRuiMingZRM opened this issue Aug 16, 2019 · 1 comment


Copy link

@ZhangRuiMingZRM ZhangRuiMingZRM commented Aug 16, 2019

  • Phalcon version: 4.0.0-beta.1
  • PHP Version: 7.3.6
  • Operating System: ubuntu
  • Installation type: Compiling from source
  • Server: php web server

In the code example

echo Str::includes('start', 'start-a-horse');

Result expect true but false given

Because strpos() or mb_strpos may return Boolean FALSE, but may also return a non-Boolean value which evaluates to FALSE

return (bool) mb_strpos(haystack, needle);

return (bool) strpos(haystack, needle);

Use === for testing the return value

  final public static function includes(string! needle, string! haystack) -> bool
        if function_exists("mb_strpos") {
            return (bool) false !== mb_strpos(haystack, needle);
        } else {
            return (bool) false !== strpos(haystack, needle);
@ZhangRuiMingZRM ZhangRuiMingZRM referenced this issue Aug 16, 2019
4 of 5 tasks complete
@sergeyklay sergeyklay added this to the 4.0.0 milestone Aug 16, 2019
@sergeyklay sergeyklay added this to To do in 4.0 Release via automation Aug 16, 2019
@niden niden moved this from To do to In progress in 4.0 Release Aug 18, 2019

This comment has been minimized.

Copy link

@sergeyklay sergeyklay commented Aug 19, 2019

Fixed in the 4.0.x branch. Feel free to open a new issue if the problem appears again. Thank you for contributing.

@sergeyklay sergeyklay closed this Aug 19, 2019
4.0 Release automation moved this from In progress to Done Aug 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
4.0 Release
2 participants
You can’t perform that action at this time.