Web hosting solutions - 71Chapter 5Syntax and VariablesThis is identical to calling

71Chapter 5Syntax and VariablesThis is identical to calling error_reporting()on the integer value of E_ALL, but is betterbecause the actual value of E_ALLmay change from one version of PHP to the next. It s also possible to create your own constants using the define()form, although this ismore unusual than referring to built-in constants. The code: define(MY_ANSWER, 42); would cause MY_ANSWERto evaluate to 42 everywhere it appears in your code. There is noway to change this assignment after it has been made, and like variables, constants that arenot part of PHP itself do not persist across pages unless they are explicitly passed to a newpage. Ultimately, you probably will not need to define constants very often, if ever. When cre- ated constants are used, they are generally most usefully defined in an external include fileand might be used for such information as a sales-tax rate or perhaps an exchange rate. Types in PHP: Don t Worry, Be HappyAll programming languages have some kind of type system, which specifies the different kindsof values that can appear in programs. These different types often correspond to different bit- level representations in computer memory, although in many cases programmers are insu- lated from having to think about (or being able to mess with) representations in terms of bits. PHP s type system is simple, streamlined, and flexible, and it insulates the programmer fromlow-level details. PHP makes it easy not to worry too much about typing of variables and val- ues, both because it does not require variables to be typed and because it handles a lot oftype conversions for you. No variable type declarationsAs you saw in Chapter 4, the type of a variable does not need to be declared in advance. Instead, the programmer can jump right ahead to assignment and let PHP take care of figuring out the type of the expression assigned: $first_number = 55.5; $second_number = Not a number at all ; Automatic type conversionPHP does a good job of automatically converting types when necessary. Like most other modern programming languages, PHP will do the right thing when, for example, doing mathwith mixed numerical types. The result of the expression$pi = 3 + 0.14159is a floating-point (double) number, with the integer 3implicitly converted into floating pointbefore the addition is performed. Types assigned by contextPHP goes further than most languages in performing automatic type conversions. Consider: $sub = substr(12345, 2, 2); print( sub is $sub
);
Searching for affordable and reliable webhost to host and run your web applications? Go to our java web server services and you will be pleased.

Leave a Reply