zephir icon indicating copy to clipboard operation
zephir copied to clipboard

[RFC] Instanceof for non objects

Open ovr opened this issue 9 years ago • 3 comments

Is it okey?

refs https://github.com/phalcon/zephir/pull/821

Error https://github.com/phalcon/zephir/blob/master/ext/kernel/object.c#L74 https://github.com/phalcon/zephir/blob/master/ext/kernel/object.c#L62

No error: https://github.com/phalcon/zephir/blob/master/ext/kernel/object.c#L84

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

ovr avatar Mar 17 '15 09:03 ovr

PHP behavior is that you can call instanceof on anything except constants. So something like

var_dump("test" instanceof STDClass);

fails, but when using a variable, any type is ok.

I do not see why we shouldn't adopt that behavior.

So I think it's safe to remove that warning/error.

steffengy avatar Mar 17 '15 09:03 steffengy

The more errors you get, the better you application can be

andresgutierrez avatar Mar 17 '15 15:03 andresgutierrez

Instead of throwing error it could assume false:

if typeof this->validation == "object" && (this->validation instanceof Validation)  && this->validation->valid() {
}
if this->validation instanceof Validation  && this->validation->valid() {}

Also https://github.com/phalcon/zephir/issues/277 would be helpful:

if !validation instanceof Validation {}

mruz avatar Sep 29 '15 07:09 mruz