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

Home » Imported messages » comp.lang.php » Something I have never seen before
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Something I have never seen before [message #169470 is a reply to message #169469] Tue, 14 September 2010 17:34 Go to previous messageGo to previous message
matt[1] is currently offline  matt[1]
Messages: 40
Registered: September 2010
Karma:
Member
On Sep 14, 1:09 pm, The Natural Philosopher <t...@invalid.invalid>
wrote:
> sheldonlg wrote:
>> On 9/13/2010 8:21 PM, Jerry Stuckle wrote:
>>> On 9/13/2010 8:07 PM, sheldonlg wrote:
>>>> In all my years of programming here is something I have never seen
>>>> before (that actually happened in a program:
>
>>>> $b = array('5', '3');
>>>> $a = (count($b) + 1)/2;
>>>> print 'count = ' . count($b) . '<br>';
>>>> print 'a = ' . $a;
>
>>>> Output:
>>>> =======
>>>> count = 2
>>>> a = 1.5
>
>>>> I just don't understand how this is possible, that a is not one.
>
>>> (2 + 1) / 2 = 1.5.
>
>>> How could it be anything else?
>
>> Wow.  I guess in all the years of PHP programming I had never before had
>> a need for integer arithmetic.  In Java, C, Fortran, etc. an integer
>> slash integer yields an integer.  In PHP (I just looked it up) it can be
>> a float.  So, I just assumed that it was the same in PHP.  I guess that
>> this is because PHP is an untyped language.
>
>> Yes, I do feel silly now.
>
> no, you have to cast your mind back to BASIC to find a language designed
> to be 'easy to use' that completely masks any possible knowledge of what
> exact type of variable is in play at any given point.
>
> And whose specification is not unambiguous on that point. Or was that
> JavaShite (TM).
>
> it's less untyped, than randomly casting types about like pearls before
> swine.
>
> whether '3' is in integer, a character, a string or a floating point
> number, is entirely down to context. And will change with it, too.
>
> Its known as programming for dummies, and its very fashionable.

And just to confuse the matter even further:

$a = 3;
$b = 2;
var_dump(is_int($a));
var_dump($a);
var_dump(is_int($b));
var_dump($b);
var_dump($a/$b);

bool(true)
int(3)
bool(true)
int(2)
float(1.5)
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Function that returns name of itself?
Next Topic: Last element in an array?
Goto Forum:
  

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

Current Time: Sat Nov 23 19:51:31 GMT 2024

Total time taken to generate the page: 0.05222 seconds