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

Closed
ZhangRuiMingZRM opened this issue Aug 16, 2019 · 1 comment
Closed

Str::includes return unexpected result #14301

ZhangRuiMingZRM opened this issue Aug 16, 2019 · 1 comment
Labels
bug A bug report status: medium Medium
Milestone

Comments

@ZhangRuiMingZRM
Copy link
Contributor

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
https://docs.phalconphp.com/4.0/en/helper#includes

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 mentioned this issue Aug 16, 2019
5 tasks
@sergeyklay sergeyklay added this to the 4.0.0 milestone Aug 16, 2019
@sergeyklay
Copy link
Contributor

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

@niden niden added bug A bug report status: medium Medium and removed Bug - Medium labels Dec 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug report status: medium Medium
Projects
None yet
Development

No branches or pull requests

3 participants