FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » switch with case 0
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: switch with case 0 [message #182614 is a reply to message #182598] Sat, 17 August 2013 20:14 Go to previous messageGo to previous message
Thomas Mlynarczyk is currently offline  Thomas Mlynarczyk
Messages: 131
Registered: September 2010
Karma:
Senior Member
Peter H. Coffin schrieb:

[PHP should never implicitly parse out anything from a string]

> But the only way to do that that's consistent is to drop "loosely typed"
> entirely,

No. Why? Other (loosely typed) languages work just fine. Because instead
of implicitly casting a string to an integer, they rather cast the
integer to a string. And there's a most natural way to do that: just use
the syntax for the respective number literal in that language (if
several different ones are possible, use the shortest representation).
Thus there are no "locale issues". (For locale specific number
formatting, there are dedicated functions.)

> Strong-typing introduces its own complications: Are we going to cast
> implicitly between numeric types? It's easy to say "Sure, that's okay"
> but we're IMMEDIATELY up against float rounding and questions of "Do we
> want an explicity DECIMAL type?" and how to compare them.

If the target type is "larger" (wider range of values) and/or "more
precise" (more decimals) than the source type, there should be no
problem. The other way round, a (lossless) type conversion may not be
possible. In that case the language could either throw an exception or
still perform the conversion with some information loss if reasonably
acceptable. E.g. if you convert a float(3.14) to int, it's clear that
the decimals will have to be dropped and the result will be int(3).
Converting a float larger than PHP_INT_MAX to int could only result in
PHP_INT_MAX (what else? `null` possibly?). Both are acceptable when done
*explicitly*. But the language should not perform such lossy conversions
*implicitly*.

Greetings,
Thomas

--
Ce n'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!
(Coluche)
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: AND and OR
Next Topic: Compiling PHP 5.x on Cygwin
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Nov 30 15:02:26 GMT 2024

Total time taken to generate the page: 0.04657 seconds