Open serebro opened 10 years ago
This bug is caused by left side not right! instance off success work with Traversable could you paste more code?
No matter what class is used (Traversable, MyClass, etc). There is problem in the priority of operations. Before INSTANCEOF, after NOT. This is not essential, but in the feature may make a problem.
This happens because !values returns a boolean value which cannot be used in a 'instanceof' operation.
PHP allows to do this because 'instanceof' has a difference precedence, but the code looks less than natural:
$a = null;
var_dump(!$a instanceof stdClass); // bool(true)
In PHP instanceof
has higher operator precedence than !
.
I think that is could be fixed, but that is not priority task, for now.
i agree with @phalcon (it works like in php)
@nkt i don't think so write php code when instanceof would be higher than operator not
@ovr please read comments in php manual about instanceof
Actually phalcon write the same opinion.
PHP allows to do this because 'instanceof' has a difference precedence, but the code looks less than natural
Examples: https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Validator/Constraints/CollectionValidator.php#L30 https://github.com/zendframework/zf2/blob/master/library/Zend/Db/Sql/Platform/AbstractPlatform.php#L64
I have the code: if !values instanceof \Traversable {}
and get this error: "InstanceOf requires a 'dynamic variable' in the left operand"
but it works if !(values instanceof \Traversable) {}
see http://www.php.net/manual/en/language.operators.precedence.php