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

In PHP 7.2, an exception is thrown if the column name is a string instead of an array when building an IN condition. #13405

Closed
vistart opened this issue Jan 18, 2017 · 6 comments
Assignees
Milestone

Comments

@vistart
Copy link

vistart commented Jan 18, 2017

What steps will reproduce the problem?

As of PHP 7.2, count() only receives an array or a class that implements Countable, and throws an exception when it encounters another type.
We look at line 1186 (2.0.10) or line 1188 (master), if $column is a string at this time, then an exception will be thrown.
As we all know, in future versions of PHP, parameter type restrictions will become more stringent.

My Solution:

Check whether the $column is an array before counting it.
for example:

if ($column instanceof \Traversable || (is_array($column) && count($column) > 1)) {
    return $this->buildCompositeInCondition($operator, $column, $values, $params);
} elseif (is_array($column)) {
    $column = reset($column);
}

Additional info

Q A
Yii version 2.0.10 & 2.0.11-dev
PHP version 7.2.0-dev
Operating system Any
@samdark samdark added the php7 label Jan 18, 2017
@samdark samdark added this to the 2.0.12 milestone Jan 18, 2017
@samdark
Copy link
Member

samdark commented Jan 18, 2017

Which class are you referring to?

@vistart
Copy link
Author

vistart commented Jan 18, 2017

@samdark Updated.
QueryBuilder.php

@samdark samdark added feature:db status:to be verified Needs to be reproduced and validated. labels Jan 18, 2017
@vistart
Copy link
Author

vistart commented Jan 18, 2017

like this job:
the reason for the 3), 4), 7) ~ 20), 22) ~ 29) etc. are same as above,

@cebe
Copy link
Member

cebe commented Jan 18, 2017

Yeah, this is known issue, many tests are failing on PHP 7.2 because of count not supporting non-arrays anymore: https://travis-ci.org/yiisoft/yii2/jobs/192891263#L305

@vistart
Copy link
Author

vistart commented Jan 28, 2017

The same problem also occurs in yii2-redis:
LuaScriptBuilder.php

@cebe cebe modified the milestones: 2.0.13, 2.0.12 Apr 26, 2017
@cebe cebe removed the status:to be verified Needs to be reproduced and validated. label Apr 26, 2017
@SilverFire
Copy link
Member

Fixed by 03d53b7

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

No branches or pull requests

4 participants