# Something I have never seen before

#### Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

•  Subject
• Author
• Posted on

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.

--
Shelly

## Re: Something I have never seen before

On 9/13/2010 8:07 PM, sheldonlg wrote:

(2 + 1) / 2 = 1.5.

How could it be anything else?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

## Re: Something I have never seen before

On 09/13/2010 08:21 PM, Jerry Stuckle wrote:

Whatever... but please just donâ€™t divide by zero. I still have a life to
live.

## Re: Something I have never seen before

On 9/14/2010 2:21 AM, Jerry Stuckle wrote:

Indeed. Sheldonlg must have a bad day.
I know how that feels. ;-)

My advise: Take a day or two to relax, then code on.

Regards,
Erwin Moller

--
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare

## Re: Something I have never seen before

On 9/13/2010 8:21 PM, Jerry Stuckle wrote:

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.

--
Shelly

## Re: Something I have never seen before

sheldonlg wrote:

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.

## Re: Something I have never seen before

wrote:

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)

## Re: Something I have never seen before

sheldonlg <sheldonlg> writes:

How on earth *could* a be one? (2+1)/2 == 1.5.

sherm--

--
Sherm Pendley
<http://camelbones.sourceforge.net
Cocoa Developer

## Re: Something I have never seen before

On 14 Sep, 01:07, sheldonlg <sheldonlg> wrote:

I agree it is pretty amazing that you have found some programming
lines that actually give the correct output!

I have seen it before, once or twice ;-)

## Re: Something I have never seen before

On Sep 13, 8:07=A0pm, sheldonlg <sheldonlg> wrote:

Are you expecting a to be one because you are thinking you're dividing
2/2, or because you realize you're dividing 3/2 and expecting integer
math?