Skip to content

Conversation

@bor0
Copy link
Contributor

@bor0 bor0 commented Jul 30, 2014

Make is_numeric() consistent. Since " 1" == 1 and "1 " == 1, is_numeric() should return true for both strings.

Make is_numeric() consistent. Since " 1" == 1 and "1 " == 1, is_numeric() should return true for both strings.
@datibbaw
Copy link
Contributor

The skip code can be put much lower inside the code, just before when the trailing length check is performed; like this.

@bor0
Copy link
Contributor Author

bor0 commented Jul 31, 2014

I don't understand how your code excludes trailing chars

@datibbaw
Copy link
Contributor

Just before the trailing length check is done, ptr is expected to be at the last character of the string, i.e. \0; so the loop consumes any white space and only then perform the check.

@sameg14
Copy link

sameg14 commented Jul 31, 2014

Am I missing something here?

php > var_dump(is_numeric(" 1"));
bool(true)

@datibbaw
Copy link
Contributor

@sameg14 Yes, it's not about the case of leading whitespace but treating trailing whitespace in the same way.

@sameg14
Copy link

sameg14 commented Aug 14, 2014

Aah ok I get it now, definitely agree this should get fixed!

php > var_dump(is_numeric("1 "));
bool(false)

@smalyshev smalyshev added the Bug label Nov 24, 2014
@KalleZ
Copy link
Member

KalleZ commented Aug 7, 2016

Wouldn't it make more sense to run php_trim() internally on this to strip both leading and exceeding whitespace in one go here?

Agreed that it should be fixed tho

@nikic
Copy link
Member

nikic commented Aug 7, 2016

@KalleZ As this code is performance-critical, using php_trim() here is not appropriate.

I'm tentatively in favor of this change, but I think that it requires an RFC (or at the least an internals discussion). The impact here is larger than just is_numeric(), this change affects many (implicit) type conversions in the language.

@bor0
Copy link
Contributor Author

bor0 commented Aug 7, 2016

@nikic, I haven't created an RFC before, but if you (or someone else) can guide me, I can try to create it :)

@krakjoe krakjoe added RFC and removed Bug labels Jan 2, 2017
@krakjoe
Copy link
Member

krakjoe commented Jan 2, 2017

@bor0 The first thing to do is start an internals discussion, to try to gauge support/consensus ... if an RFC is necessary it will soon become apparent.

You could also give this as read.

Also, this has merge conflicts (not that important, nobody can merge it without consensus whatever).

@krakjoe
Copy link
Member

krakjoe commented Jul 10, 2017

Having waited 6 months for this 3 year old PR to get moving, I'm quite confident that this is going nowhere, so I'm closing the PR.

Please take this action as encouragement to move forward with a clean PR and RFC.

@krakjoe krakjoe closed this Jul 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants