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

error_reporting has influence on behavior of collection->where() #22106

Closed
leonrenkema opened this issue Nov 16, 2017 · 1 comment
Closed

error_reporting has influence on behavior of collection->where() #22106

leonrenkema opened this issue Nov 16, 2017 · 1 comment

Comments

@leonrenkema
Copy link

  • Laravel Version: 5.5.11
  • PHP Version: 7.1.11 & 7.1.3

Description:

When I change error_reporting to E_NONE the behavior of Collection->where changes and then a unit test fails.

Steps To Reproduce:

I have forked the repository and used travis to check. This build fails because of a unit test that is failing https://travis-ci.org/leonrenkema/framework/builds/303214891.

The only file I have changed is tests/Support/SupportCollectionTest.php for the sake of testing and executed error_reporting(0). Changing php.ini also works.

Cause

The test works because of a PHP notice that gets generated when a stdClass is compared with an integer. With error reporting on Object of class stdClass could not be converted to int will be generated and catched and returns false.

But when error_reporting is off there is no error generated and this function will return true.

Illuminate/Support/Collection.php:484

try {
    switch ($operator) {
        default:
        case '=':
        case '==':  return $retrieved == $value;
        case '!=':
        case '<>':  return $retrieved != $value;
        case '<':   return $retrieved < $value;
        case '>':   return $retrieved > $value;
        case '<=':  return $retrieved <= $value;
        case '>=':  return $retrieved >= $value;
        case '===': return $retrieved === $value;
        case '!==': return $retrieved !== $value;
    }
} catch (Exception $e) {
    return false;
}
@themsaid
Copy link
Member

Thanks for this catch, here's a PR with a fix: #22172

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants