+ 19

Why php is called loosely typed language ?

19th Mar 2019, 3:30 PM
Jay Suthar
Jay Suthar - avatar
6 Answers
+ 12
In PHP you can do things like `10 + "10" + true` and it it will run fine (the result is 21). Here PHP automatically converted different types to numbers, which is called type coercion. Strongly typed languages would throw an error here, because you can't add numbers and strings. PHP also allows you to declare a variable as one type, and then switch types. For example $x = 10; $x = "Hello"; will run without problems; strongly typed languages would throw an error here, because $x was first defined as a number, and you can't store a string in a number variable. Weak/Loose typing has fallen out of fashion a bit because it can lead to many bugs.
19th Mar 2019, 3:57 PM
Schindlabua
Schindlabua - avatar
+ 4
Loosely typed languages refer to those programming scripts that do not require defining the variable. To put it simply, while declaring a variable in these programming scripts, there is no need of defining or classifying the data type stored in them.
28th Jan 2020, 10:56 AM
Amrita Roy
Amrita Roy - avatar
0
hello
2nd Apr 2019, 9:36 PM
Myguel Freitas Freitas
Myguel Freitas Freitas - avatar
- 1
$×=10
2nd Apr 2019, 9:37 PM
Myguel Freitas Freitas
Myguel Freitas Freitas - avatar
- 1
Hlo
3rd Apr 2019, 7:38 AM
Suman Kumar
Suman Kumar - avatar
- 1
I have no idea sorry
3rd Apr 2019, 8:37 AM
Sarah Smith
Sarah Smith - avatar