+ 2

Why PHP is using generic data type and not specific ones?

I was just thinking.. All major high level programming languages (except python) have specific data types (bool, char, int and such). PHP can really benefit for both readability (PHP files can become really messy really fast) and efficiency from using specific deceleration of data types (the conversion is happening behind-the-scenes anyway). So, why PHP uses such format?

29th Mar 2017, 10:58 AM
anon
anon - avatar
4 Antworten
+ 2
not in a direct way, as in bool x = 5. those data types are being set behind the scene depends on the value, same as in PHP. you can cast in python using datatypes but that's pretty much it
29th Mar 2017, 3:13 PM
anon
anon - avatar
+ 1
I can't help with PHP, but Python does have int, bool, str, float, etc data types.
29th Mar 2017, 1:42 PM
Igor B
Igor B - avatar
+ 1
anon PHP is considered loosely typed. Its variables have no problem changing type. PHP tries real hard to select the right type based on context. Sometimes it fails, but rather than produce a compiler error, just something unexpected will happen. C# and a lot of other languages are tightly (or "strongly") typed. Every variable has to have a type defined, and that type can't really be changed. They're different because of the nature of the language and their vastly different origins. I like php's loosely typed style, but I think it gets a bad wrap because a lot of programmers don't know the details enough to sufficiently account for its nuances. From experience working with C# and other people's code, C# might be arguably easier to read because the type is specified and does not change.
6th Sep 2018, 5:07 AM
Joshua Kersey
Joshua Kersey - avatar
- 1
you can also cast in php like int (10 / 3) to return an integer value.
30th Mar 2017, 8:20 AM
Freeborn
Freeborn - avatar