Skip to content

Deprecated error: passing null to strlen #37

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

Closed
niconoe- opened this issue Feb 15, 2022 · 2 comments
Closed

Deprecated error: passing null to strlen #37

niconoe- opened this issue Feb 15, 2022 · 2 comments

Comments

@niconoe-
Copy link
Contributor

niconoe- commented Feb 15, 2022

I tried the v0.8.0 on one of my project and I got the following error

Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/www/vendor/rskuipers/php-assumptions/src/PhpAssumptions/Cli.php on line 138

I ran the project in a docker container that own a PHP 8.1 version.

To fix it, the following line :
https://github.com/rskuipers/php-assumptions/blob/master/src/PhpAssumptions/Cli.php#L138

could definitly be replaced by

if ($list !== '') {

as the only purpose of the usage of strlen here is to check if the string is not empty.

EDIT: the only usage I found is actually here:

$excludes = $this->getPathsFromList($this->cli->arguments->get('exclude'));

After a quick look at \League\CLImate\Argument\Manager::get method, I found out it can return null. As the argument of getPathsFromList is supposed to be a string (read from PHPDoc + inferred from usage in the method), I think a cast should be executed while passing the argument:

$excludes = $this->getPathsFromList((string)$this->cli->arguments->get('exclude'));

Indeed, the return type of \League\CLImate\Argument\Manager::get is string|int|float|bool|null, all of them castable to string.

rskuipers added a commit that referenced this issue Feb 15, 2022
@rskuipers
Copy link
Owner

Thank you for your contribution and the detailed explanation!

I merged it and I've created a new tag you can now use: https://github.com/rskuipers/php-assumptions/releases/tag/0.8.1

@niconoe-
Copy link
Contributor Author

You're welcome! I liked to contribute 👍

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