Sunday, June 30, 2013

Type Juggling and Type Casting



Type Juggling:
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.

PHP data types



In PHP we have 8 primitive data types. They are categorized into 3 basic categories – scalar, compound, and special. It’s also important to note that PHP is a dynamically typed language.

Variable types and Variable Scope




The scope of a variable in PHP is the context in which the variable was created, and in which it can be accessed. Essentially, PHP has 2 scopes: