PHP is a loose type language, in the sense that you don't need to specify the variable type when you declare a variable. The variable takes the data type of the value that is assigned to it.
$variable1 = 5; $variable2 = $variable1; $string_variable = 'This is a string'; $float_variable = 343.34; $object_variable = new StdClass();
|Small visualization that i made to represent the symbol table|
A Symbol table is an array that maps variable names to the positions of their values in memory. When you copy a value from one variable to another, PHP dose not get more memory for a copy of the value to store it. Instead, it updates the symbol specifying that both the variables are pointing to the same part of memory.
$name = 'John'; // Stored at hex100 = 'John' - Reference count is 1 $temp = $name; // Still Stored at hex 100 = 'John' - Reference count is 2;
$name = 'scott'; // Stored at hex100 = 'Scott' - Reference count becomes 1 $temp = 'John'; // Allocated new memory address hex104 - Reference count is 1.
I'm Tamil Selvan, a Passionate Programmer, Web Designer/Developer, Blogger and Gamer. I love Designing and Creating new things that helps and inspires users. Living in Chennai, India.