Home > Article > Backend Development > Is php a strongly typed language?
Weakly typed languages allow a piece of memory to be viewed as multiple types. For example, directly add integer variables and character variables. C and C are static languages, but also weakly typed languages; Perl and PHP are dynamic languages, but also weakly typed languages.
PHP is a weakly typed language
We note that it is not necessary to declare this variable to PHP data type.
PHP will automatically convert the variable to the correct data type based on its value. (Recommended learning: PHP programming from entry to proficiency)
In a strongly typed programming language, we must declare (define) the variable before using it Type and name.
Strong and weak types
strongly typed: If all programs in a language are well behaved - that is If forbidden behaviors are not possible, the language is strongly typed.
Weak type weakly typed: Otherwise, it is weakly typed. For example, buffer overflow in C language belongs to trapped errors, that is, forbidden behaviors. Therefore, C is a weak type.
People in front also said that in weakly typed languages, type checking is less strict, and it is more tolerant. Implicit type conversion. For example, int in C language can be turned into double. The result is: it is easy to produce forbidden behaviors, so it is weakly typed
Dynamic, static type
static type statically: If the ill behaved program is rejected at compile time, It is statically typed;
Dynamic type dynamiclly: If ill behaviors are rejected at runtime, it is dynamiclly typed.
Misunderstanding
Everyone thinks that C language needs to write int a, int b and the like, but Python does not need to write (you can write a, b directly), so C is static , Python is dynamic. This understanding is not accurate enough. For example, Ocaml is statically typed, but it doesn't need to be written explicitly. .
Ocaml is a static implicit type
Static types can be divided into two types:
If the type is part of the language syntax, it is explicitly typed Explicit type;
If the type is deduced at compile time, it is implicitly typed, such as ML and Haskell
The above is the detailed content of Is php a strongly typed language?. For more information, please follow other related articles on the PHP Chinese website!