ovr / phpsa

Smart/Static Analyzer(sis) for PHP :bowtie::neckbeard:
Other
637 stars 77 forks source link

[Bug] error in_array() expects parameter 2 to be array, null given #331

Closed terra-yi closed 7 years ago

terra-yi commented 7 years ago

Even when PHPSA\CompiledExpression instance returns true in ::isArray() method call, the variable itself could contain null instead of an array value. Hence it could produce PHP warning/error on line 38 when it calls in_array() on $var->getValue()

PHP Warning: in_array() expects parameter 2 to be array, null given in vendor/ovr/phpsa/src/Compiler/Expression/ArrayDimFetch.php on line 38

Either

if (!$var->isArray()) { => if (!$var->isArray() || !is_array($var->getValue())) { on line 28 in ArrayDimFetch class

or

return $this->type === self::ARR; => return ($this->type === self::ARR && is_array($this->value)); on line 294 in CompiledExpression class

or

add certain validation on creation of CompiledExpression instance

would be recommended.

ovr commented 7 years ago

Hey! Thank you for bad reporting, I will take a look tomorow