68Part IPHP: The BasicsIt s conceivable that you (Web and email hosting) will
68Part IPHP: The BasicsIt s conceivable that you will want to actually print the preceding math expression ratherthan evaluate it. You can force PHP to treat a mathematical variable assignment as a string by quoting the expression: $pi = 3 + 0.14159 ; Reassigning variablesThere is no interesting distinction in PHP between assigning a variable for the first time andchanging its value later. This is true even if the assigned values are of different types. Forexample, the following is perfectly legal: $my_num_var = This should be a number hope it s reassigned ; $my_num_var = 5; If the second statement immediately follows the first one, the first statement has essentiallyno effect. Unassigned variablesMany programming languages will object if you try to use a variable before it is assigned; others will let you use it, but if you do you may find yourself reading the random contents ofsome area of memory. In PHP, the default error-reporting setting allows you to use unassignedvariables without errors, and PHP ensures that they have reasonable default values. If you would like to be warned about variables that have not been assigned, you should changethe error-reporting level to E_ALL(the highest level possible) from the default level of errorreporting. You can do this either by including the statement error_reporting(E_ALL); at the top of a script or by changing your php.inifile to set the default level (see Chapters 30and 31). Default valuesVariables in PHP do not have intrinsic types a variable does not know in advance whetherit will be used to store a number or a string of characters. So how does it know what type ofdefault value to have when it hasn t yet been assigned? The answer is that, just as with assigned variables, the type of a variable is interpreteddepending on the context in which it is used. In a situation where a number is expected, anumber will be produced, and this works similarly with character strings. In any context thattreats a variable as a number, an unassigned variable will be evaluated as 0; in any contextthat expects a string value, an unassigned variable will be the empty string (the string that is zero characters long). Checking assignment with IsSetBecause variables do not have to be assigned before use, in some situations you can actuallyconvey information by selectively setting or not setting a variable! PHP provides a functioncalled IsSetthat tests a variable to see whether it has been assigned a value. As the following code illustrates, an unassigned variable is distinguishable even from a vari- able that has been given the default value: $set_var = 0; //set_var has a value//never_set does notprint( set_var print value: $set_var
); Cross- Reference07
From our experience, we can recommend PHP5 Web Hosting services, if you need affordable webhost to host and run your web application.