Mac os x web server - 72Part IPHP: The BasicsThe substrfunction is designed to
72Part IPHP: The BasicsThe substrfunction is designed to take a string of characters as its first input and return asubstring of that string, with the start point and length determined by the next two inputs tothe function. Instead of handing the function a character string, however, we gave it the inte- ger 12345. What happens? As it turns out, there is no error, and we get the browser output: sub is 34Because substrexpects a character string rather than an integer, PHP converts the number12345to the character string 12345 , which substrthen slices and dices. Because of this automatic type conversion, it is very difficult to persuade PHP to give a typeerror in fact, PHP programmers need to exercise a little care sometimes to make sure thattype confusions do not lead to error-free but unintended results. Type SummaryPHP has a total of eight types: integers, doubles, Booleans, strings, arrays, objects, NULL, andresources. .Integersare whole numbers, without a decimal point, like 495. .Doublesare floating-point numbers, like 3.14159 or 49.0. .Booleanshave only two possible values: TRUEand FALSE. .NULLis a special type that only has one value: NULL. .Stringsare sequences of characters, like PHP4.0supportsstringoperations. .Arraysare named and indexed collections of other values. .Objectsare instances of programmer-defined classes, which can package up both otherkinds of values and functions that are specific to the class. .Resourcesare special variables that hold references to resources external to PHP (suchas database connections). Of these, the first five are simple types, and the next two (arrays and objects) are compound the compound types can package up other arbitrary values of arbitrary type, whereas thesimple types cannot. We treat only the simple types in this chapter, since arrays (Chapter 9) and objects (Chapter 20) need chapters all to themselves. Finally, the thorniest details of thetype system, including discussion of the resource type, are deferred to Chapter 25. The Simple TypesThe simple types in PHP (integers, doubles, Booleans, NULL, and strings) should mostly befamiliar to those with programming experience (although we will not assume that experienceand will explain them in detail). The only thing likely to surprise C programmers is how fewtypes there are in PHP. Many programming languages have several different sizes of numerical types, with the largerones allowing a greater range of values, but also taking up more room in memory. For exam- ple, the C language has a shorttype (for relatively small integers), a longtype (for possiblylarger integers), and an inttype (which might be intermediate, but in practice is sometimesidentical either to the shortor longtype). It also has floating-point types, which vary intheir precision. This kind of typing choice made sense in an era when tradeoffs between07
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision best web hosting services