Type Juggling

Type Juggling means dealing with a variable type. In PHP a variables type is determined by the context in which it is used. If an integer value is assigned to a variable, it becomes an integer.

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
 $phpcodez = "1"; // $phpcodez is string (ASCII 49)
 $phpcodez *= 2; // $phpcodez is now an integer (2)
 $phpcodez = $phpcodez * 1.3; // $phpcodez is now a float (2.6)
?>
Share

Leave a Reply

Your email address will not be published. Required fields are marked *