Just found out that MySQL uses the same implicit conversion precedence on SQL clauses. That shows me that possibly exists some "higher order" rule that states this consistency, and changing that is outside the scope of PHP.
On Thu, Jun 13, 2013 at 9:20 AM, Stuart Dallas <stu...@3ft9.com> wrote: > On 13 Jun 2013, at 12:27, BUSCHKE Daniel <daniel.busc...@nextiraone.eu> > wrote: > > > Hi, > > > >> It gives up when it finds a non-numeric character (as the documentation > would tell you) > > > > Why is PHP doing that? I know it works as designed and I know it is > documented like this but that does not mean that it is a good feature, does > it? So lets talk about the question: Is that behaviour awaited by PHP > software developers? Is that really the way PHP should work here? May we > should change that?! > > > > BTW: I talked to some collegues and friends since my first post. They > all guessed that "'PHP' == 0" is false within a few seconds. I think the > weak-typed-PHP is a little to weak at this point. > > I don't know what the actual reasoning is; if you want that I suggest you > ask on the internals list, but be careful how you phrase the question. If > it's pure curiosity then that's fine, but whether you agree with the > reasoning or not it's gone way past the point where it can be changed. > > My take it that the behaviour is perfectly reasonable. When you compare > two different types it has to convert one of them. If you're comparing a > string to a number it seems logical to me that the number should be the > preferred type, so the string gets converted. What would you expect > array(5) == 5 to give you? Would you expect the 5 to be converted in to an > array? No. The reason it looks odd for "PHP" == 0 is that there's no reason > why the 0 should not be converted to "0", except that strings and numbers > are not the only types available and there has to be an order of > precedence. And consistency is key. > > As for how strings get converted to numbers I have no idea why it will > take everything up to the first non-e|E|. character. The documentation > simply states the behaviour and doesn't go in to why. However, I have to > ask why it matters? Why would you want to convert > '8315e839da08e2a7afe6dd12ec58245d' to an integer? If you have code that's > juggling it automatically, be more explicit. It's fine to be interested in > the reasons why it does what it does, but if it's causing you problems then > the issue is with your code not being explicit enough, not PHP. > > -Stuart > >  http://php.net/language.types.string#language.types.string.conversion > > -- > Stuart Dallas > 3ft9 Ltd > http://3ft9.com/ > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >