Các bác PHP luôn phải thừa nhận về tính lỏng lẻo của việc khai báo dữ liệu cho biến. Nhiều người kêu là mềm dẻo, nhưng mà thực ra mềm dẻo tốn tiền. Đây là thú nhận mộc mạc của PHP.
PHP does not require (or support) explicit type definition in variable declaration; a variable’s type is determined by the context in which the variable is used. That is to say, if a string value is assigned to variable $var, $var becomes a string. If an integer value is then assigned to $var, it becomes an integer.
An example of PHP’s automatic type conversion is the multiplication operator ‘*’. If either operand is a float, then both operands are evaluated as floats, and the result will be a float. Otherwise, the operands will be interpreted as integers, and the result will also be an integer. Note that this does not change the types of the operands themselves; the only change is in how the operands are evaluated and what the type of the expression itself is.
Tóm váy lại là loại dữ liệu của biến phụ thuộc vào ngữ cảnh.