-
-
Notifications
You must be signed in to change notification settings - Fork 468
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
Untenable situation with null values #1835
Comments
This comment was marked as abuse.
This comment was marked as abuse.
Basically, Zephir should handle Not always From sources...
|
This comment was marked as abuse.
This comment was marked as abuse.
So the answer is no, this isn't a bug, but a side effect of how PHP (and the Zend engine that powers it) create and store variables. What PHP considers a The official PHP releases are written in C, with an architecture called the Zend engine serving as the interpreter, as well as the interface for extensions to access/be accessed by PHP code. Zephir code is translated to this Zend/C level, then compiled using the same mechanisms any other extension uses - which also means it's subject to the same limitations, such as complexity accessing/identifying underlying variable values. Could this be improved, somehow? Maybe. But is it a bug? Not really. Just an oddity of the underlying architecture. |
This comment was marked as abuse.
This comment was marked as abuse.
This comment was marked as abuse.
This comment was marked as abuse.
This is the same bother with null you get in MySQL. For reference: FATMOUSE + YOU = FATMOUSE Replace FATMOUSE with NULL and now you know how it works. The problem is not concisely explained. What's happening here is that it's doing this:
As in it does something strange that would almost never be needed.
Shifting the burden doesn't solve anything and I really doubt this is mandatory. In fact I'm sure of it, it's just how the language is designed. PHP just turns it's byte code into C in runtime. If PHP can handle it, so can anything else. To blame PHP/C internals for zephir not being able to do something PHP/C internals do that zephir is meant to replicate is point blank codswallop. You have PHP with pipeline of PHP -> INTERNAL. It does it fine. You have then the pipe line of ZEPHIR -> INTERNAL. The problem is INTERNAL? I don't think so. What's more likely here is that you've got one null to rule them all when under the hood you've got zval NULL, pointer NULL, key not in array, uninitialized zval, etc. PHP's null is not always perfect either. If you notice how in JS you have separate undefined and null. In PHP if you deref a non-existent key you get null rather than any kind of undefined value, in fact the only thing PHP has to represent undefined in that case is null. If you don't have notices on then with $arr['key'] returning null you don't know if it's because the key is not there or the key is set to null, so you have to use array key exists the same problem as having to use is null here. Basically null gets tossed back at you for all kinds of situations as a default and it's ambiguous which is in play. As in on fail return null, always, it's the universal exception, ubitquitous. The thing is people would expect with What if asignment has higher precedence? Try If you check the documentation zephir has no precedence. I think the developers took marketing seriously on that one. So you have to wrap EVERYTHING in brackets. Don't worry though, JS is foobar as well also doing the same for undefined. Console:
In fact there's yet another type missing, unassigned, which should in this case toss an exception as it's being assigned. Rambling aside, I'd categorically consider this a design defect at the least. |
This comment was marked as abuse.
This comment was marked as abuse.
If you have |
This comment was marked as abuse.
This comment was marked as abuse.
Work is in progress to standardize variable initialization when it can be nullable. Closing. |
@sergeyklay I've been working with both Zephir
0.10.15
and0.11.11
and to my horror I discovered the very sad state ofnull
.Basically
==
doesn't work in any contexts. Nor does===
work.is_null
and theempty
operator both work correctly but only if the variable was initialized to null. Here is the real kicker though:var_export
will always print the variable asnull
. Huh, so much for debugging with error logs. That is why it seemed like I was debugging polymorphic Heisencode.Yeah well, Dave's an idiot. Well guess what? So are you guys @niden @CameronHall for approving and merging my PR when I removed the explicit setting of the values to null. It obviously doesn't work correctly in all circumstances and who knows what the consequences of those misconfigured nulls can be down the road. It could act super weird in some circumstances. Its not even a PHP value, its a weirdo value.
null
is just TOO DAMN ARCANE as it is now. There needs to be compiler protection or something. Also why doesn't==
or===
work as expected? I guess that now I need to audit every use of null checking throughout my extension because its only working by luck.Output:
The text was updated successfully, but these errors were encountered: