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 in to the BaseArrayHelper::getValue() #19589

Closed
lav45 opened this issue Sep 20, 2022 · 5 comments
Closed

Error reporting in to the BaseArrayHelper::getValue() #19589

lav45 opened this issue Sep 20, 2022 · 5 comments
Milestone

Comments

@lav45
Copy link
Contributor

lav45 commented Sep 20, 2022

What steps will reproduce the problem?

error_reporting strrpos(): Passing null to parameter #1 ($haystack) of type string is deprecated
line 209
code 8192
file /var/www/vendor/yiisoft/yii2/helpers/BaseArrayHelper.php

Additional info

Q A
Yii version 2.0.46
PHP version 8.1
Operating system Linux
@rob006
Copy link
Contributor

rob006 commented Sep 23, 2022

In what scenario you're getting such error? getValue() does not accept null as $key.

@lav45
Copy link
Contributor Author

lav45 commented Sep 23, 2022

and who forbids doing this?
It may be worth throwing out the default value right away, so as not to provoke a similar problem in the keyExists() method

    public static function getValue($array, $key, $default = null)
    {
        if (empty($key)) {
            return $default;
        }
    }

@rob006
Copy link
Contributor

rob006 commented Sep 23, 2022

and who forbids doing this?

It does not matter. Yii cannot use types in method signature due to supported PHP versions range, but it does not mean we should add guards for every possible misuse of any method in framework. If phpdoc does not allow to pass null as $key, then it is on you if you decide to ignore it and pass null anyway.

@samdark
Copy link
Member

samdark commented Sep 25, 2022

In this case I think a safeguard would not hurt.

@rob006
Copy link
Contributor

rob006 commented Sep 25, 2022

In this case I think a safeguard would not hurt.

It may hide potential errors. That is the point why PHP started to emit deprecation for such cases. By adding bling guards Yii negates progress made by PHP. And if we're fine with that and decide that null is valid key, it should be reflected by phpdoc and probably fixed in keyExists() too.

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

3 participants