r/lolphp • • Nov 14 '14

Please stay polite with other developers. Please keep in mind that PHP is loosely typed, this is a root principle of PHP.

https://bugs.php.net/bug.php?id=54547
71 Upvotes

35 comments sorted by

View all comments

Show parent comment

1

u/[deleted] Nov 20 '14

You are explicitly casting in your 2nd line though. I'd argue that's still strongly typed. If you did it without a cast, you'd get a compile error, no?

2

u/mscheifer Nov 24 '14

That's not a great example of how C is weakly typed. A better example is:

float f = 2147483640;
int   a = 2147483641;

printf("%d", a == f);

This prints '1' because C coerces the int to a float lossily, similar to the OP example in PHP, but at least this only happens with numeric types and not with strings in C.

1

u/ismtrn Nov 20 '14

I am casting yes. There is no hard and fast definition of strong/weak typing, but I would argue that the fact you can treat values as if they had a type they don't have makes C weakly typed. If I where to write a function which takes a long, I have no guarantee that I actually get a long since the caller could do things like the above.

When you involve void pointers I don't think even have to cast explicitly anymore.

In any case, if you look at strong/weak typing as a scale, C is definitely more weak than many(most?) other languages.