-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Parser considers 0 in "$foo[0]" to be a string instead of an int #325
Comments
Isn't this left like this intentionally? See comment in https://github.com/nikic/PHP-Parser/blob/master/grammar/php5.y#L647 |
Testing using ArrayAccess doesn't really tell you how PHP "originally" interpreted it, because constant integer string indexes are normalized to integer indexes during compilation, see for example https://3v4l.org/PFZWp (this uses three strings, and yet two of them dump as integers). However, I do agree that we should be representing this as integers, consistent with how the php ast represents this: http://lxr.php.net/xref/PHP-MASTER/Zend/zend_language_scanner.l#1719 |
@martinsik "Alternative syntax" refers to the |
Implemented in 70319e2. |
@nikic Gah, I thought automatic intish string => int conversion was only a thing that happened with arrays, not all Thanks for the prompt fix, it works now. :) |
I'm having second thoughts about this change due to c1e0bab. PHP 7.1 adds support for Particularly concerning is that the offset might be This would require special handling at some point. If an |
@nikic That makes sense to me. I would expect pretty printing |
I've fixed the pretty-printing issue (along with a couple other things) in 58970e2. Still not sure whether the string->number conversion here is worthwhile. |
I expected
Scalar_LNumber
instead ofScalar_String
.PHP apparently considers it an integer (but not if it's not intish):
https://3v4l.org/qU9E9
The text was updated successfully, but these errors were encountered: