Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Even given that it was undefined behaviour to start with

On the other hand, 1. high-level languages have no reason to have UBs, especially for the trivial calling of a core function and 2. one could expect behavior in this context to be coherent with behavior in userland contexts. In PHP, using strings in a numeric context wasn't — last time I checked — considered abnormal, no matter how little sense it makes. One could therefore expect the relevant coercitive calls to be performed as they would usually be.

> it's the very first incompatible change listed

It is very ambiguously worded: the clause states functions will return NULL when passed incompatible parameters, but in all of PHP's userland code strings are very much compatible with floats. I would therefore submit that — in the context of being a user of PHP — the clause does not apply to this case as the value passed in is absolutely compatible with parameter expectations.



"high-level languages have no reason to have UBs, especially for the trivial calling of a core function"

What should a lisp implementation return when (car '()) is evaluated? How does a arbitrarily chosen return value differ from a undefined behavior?

Is "" -> 0 a standard conversion in PHP? I get it if we consider the groups (String, +) and (Float, +), but 0 is hardly the standard identity value.


> How does a arbitrarily chosen return value differ from a undefined behavior?

In it being defined, don't you think?

> Is "" -> 0 a standard conversion in PHP?

Erm... yes? `(float)""` returns that, `"" + ""` returns that, `0 + ""` returns that, and so do `intval('')`, `(int)''` or `floatval('')`. More generally, http://www.php.net/manual/en/language.types.string.php#langu...:

> When a string is evaluated in a numeric context, the resulting value and type are determined as follows [...] The value is given by the initial portion of the string. If the string starts with valid numeric data, this will be the value used. Otherwise, the value will be 0 (zero).

> 0 is hardly the standard identity value.

0 remains the standard and defined numeric value of an arbitrary string not prefixed with numeric data in PHP.


If a function in case of bad inputs returns a value in it's codomain, you can't distinguish it from a value returned by a normal call (except in cases where it falls outside of the functions image). This in my opinion is same as undefined behavior. Don't trust the value returned, if inputs were bad.

You know, I didn't actually know that. Thank you for enlightening me.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: