What is Type Juggling?

December 19, 2009 | Filed Under PHP | Comments Off

Juggling means

throwing and catching several objects simultaneously.

Type Juggling in php  means automatically type conversion.

That is to say, if a string value is assigned to variable $var$var becomes a string. If an integer  value is assigned to $var, it becomes an integer.

Please see Example.

<?php
$var = "0";// $var is string (ASCII 48)
$var += 10; // $var is now an integer (10)
$var = $foo+ 1.5; // $var is now a float (11.5)
$var = 5 + "10 Little hots"; // $var  is integer (15)
$ var = 5 + "10 Small hots"; // $var  is integer (15)
?>

$var variable comes many times in different data type.

Often it became interger, float.

This is Type Juggling in php.

Thank you

Comments

Comments are closed.

© PHPInterviewQuestion.com 2009 - 2012

eXTReMe Tracker