
PROGRAMMING PHP 5 The Next Generation Onward and upward Of all the programming languages to have emerged in recent years, PHP is one of the great success stories. It has fostered a loyal community of devel- opers and, despite some well documented issues, still maintains its popularity. BY STEVEN GOODWIN www.space -center- bremen.de oes its latest incarnation, PHP 5, find the original documentation lurking PHP community was also growing by do justice to its heritage, or is it at [1]. leaps and bounds: a number of third Ddestined to become a skeleton in PHP as we know it really began with party databases were now supported, the the closet? Steven Goodwin finds out. version 3, released in June 1998. Unlike PEAR repository came into being, and the upgrade status to PHP/FI 2.0, PHP 3 the documentation had grown into a You’re History was a complete rewrite by Rasmus, comprehensive, and very usable, online The first version of PHP was written in along with Andi Gutmans and Zeev manual [2], currently available in 26 dif- 1994 by Rasmus Lerdorf and constituted Suraski. From a technical standpoint, it ferent languages. a number of Perl scripts for building web was very much improved, and more PHP5 is claimed to be the latest and pages. The term PHP/FI was coined in capable of dealing with high volume web best version of PHP, utilizing another 1995, and was followed by PHP/FI 2.0 in sites and e-commerce applications. It new code engine (Zend 2), an impressive 1997, with PHP/FI standing for Personal also featured the first signs of object ori- new object model and a host of new fea- Home Page / Forms Interpreter. Even entation (see Box: Uh Oh!), and a though some of the functionality that we change of acronym to the still-in-use, Uh Oh! know today was present in these early PHP: Hypertext Preprocessor. Object Orientation is more a paradigm than versions, beyond a small cult group of Version 4 was essentially an extension it is any particular type of programming. developers, it was largely unheard of. of 3, using the same syntax and seman- When used correctly,its benefits include Curious readers and history students can tics. It featured output buffering, code re-use,abstraction of detail,data improved object orientation, and various encapsulation and polymorphism.The When builders go down new features (like references) and implementation of an OO solution involves the pub they talk about instructions, such as the foreach control objects,a much over-used term that (in this football. Presumably structure. Behind the scenes too, a lot instance) indicates that both the data,and therefore,when foot- HOR had changed, as the PHP code base had the code that manipulates it,are bound T ballers go down the together in one unit. Each object is often pub they talk about been modularized and optimized, with represented by a class.The data held within builders! When Steven Goodwin goes some code running over 200 times faster. this class represents its current state,and down the pub he doesn’t talk about This was largely thanks to a new THE AU football. Or builders. He talks about the code that affects it are called methods, computers. Constantly… engine, known as Zend, which was a or member functions. complete re-write of the original. The 64 July 2004 www.linux-magazine.com PHP 5 PROGRAMMING tures. It has gone through four beta ver- vice to the backwards compatibility capitalized) are used for the extensions sions with, at the time of writing, the issue. The core language looks no differ- like SQLite and SOAP. current version standing at Release Can- ent to that of PHP 4 and although there There are a slew of new functions in didate 2, made available on the 25th have been a few backwards incompati- PHP 5, all detailed in [6]. Most of them April 2004. It is claimed stable, but “still ble changes, these have been in the provide better support for the core lan- not recommended for mission-critical name of stricter standards, and are guage, although most have been use”. True stability will come with time, detailed in [5]. available before in libraries, or as user- although the experiments of this author If your code is polite and follows the added comments in the standard have shown it perfectly usable for small described function behavior to the letter, documentation on the main PHP site [2]. to medium scale work. most of these changes won’t affect you, These functions break down into five but be warned as array_merge now only basic groups. See Table 1. Little Fluffy Clouds accepts arrays. This may cause E_WARN- Before we launch into specific details The source code for PHP 5 can be down- INGs to appear without apparent reason. of some of these features, there are two loaded from [3] as a five MByte tarred It is worthwhile to note that illegal string development functions to highlight. The gzip file, although the only official bina- offsets are now considered errors (not first is var_dump which has an improved ries available are for Windows. Brave warnings). Note also that, look, and expands the information inside Debian users can grab the .debs from [4] the class, as does print_r. by adding the line, $app.is_object() // Example of var_dump deb http://packagesU returns an object and one needs to use object(MyName)#5 (2) { .dotdeb.org ./ the modern form, ["firstName"]=> string(6) "Steven" to their /etc/apt/sources.list, although is_object($app) ["lastName"]=> this will not be guaranteed to work. string(7) "Goodwin" Assuming you’re compiling from source to get a boolean value. However, most } the traditional trio is employed thus, practical code will not (or should not!) have these errors present. For the termi- The second is a new function called $ ./configure --with-mysql U nally paranoid there is a compatibility debug_backtrace, which returns an array --with-apxs mode. This can be used to determine showing the call stack. This has been $ make whether the bug is in your code, or the partially back ported into PHP 4, but # make install new PHP 5 interpreter. It can be con- looks to be a stalwart for all PHP devel- trolled with the line, opers looking for quick, light weight, The options for ./configure may need to debugging assistant, without resorting to be adapted, depending on whether you zend.ze1_compatibility_modeU xdebug. have (or want) MySQL support. The pri- =Off mary dependency essential for PHP 5 is a The Invisible Man recent version of libxml2 (version 2.5.10 in your php.ini file. Two sample ini files Among the list of core language features or above), but once that’s available, a come with PHP 5, a development version there’s a small selection that has been basic compile and install can be accom- and a more secure release version. devoted to code that doesn’t exist! That plished with a fairly minimal time outlay. Although neither sees the need to use is, if a non-existent class method is called, Documentation is included in the pack- the compatibility mode. the special __call function is invoked. age, which also details how to run PHP 4 Developers working on the bleeding and 5 alongside each other. If you’re edge will also have realized that studly- class Reverse { compiling PHP 5 as an Apache module, Caps (first word in lower case, and the function __call($function, U then the traditional rules for building initial letter of every other word being $arguments) DSO’s (Dynamic Shared { Object) apply. Table 1: New function groups return strrev($function); } Area Number Notes A Grand Don’t Come } Arrays 6 Mostly to determine differences between For Free arrays The first, most obvious, ques- InterBase 19 Various functions for Interbase users $r = new Reverse; tion with such a new system iconv 7 Handles internationalization features,and print $r->this_doesnt_exist(); is a consideration of old code. MIME headers Does it break anything? Is Streams 8 Most supplying useful low level socket Or, if you try to access a member vari- this a backwards step? Fortu- handling functionality able that doesn’t exist, one of two nately, the answer appears to Misc 34 General purpose functions,including PHP different functions will be called, syntax checker,string conversion and process be no. Most of the changes in control depending on whether you tried to read this release have paid lip ser- from, or write to, the variable. www.linux-magazine.com July 2004 65 PROGRAMMING PHP 5 01 class Length the appropriate class files at the start, ples, which makes it easier for PHP 5 02 { compared to sporadic on-demand load- developers to interact with them. 03 function __get($variable_U ing (which may include disk seek times) There are two main areas of object ori- name) throughout the script’s lifetime. ented study in PHP 5. The first are the 04 { Be careful when using __autoload changed features. These are cases where 05 return strlen($variable_U since file names are case-sensitive, but improvements have been made to the name); PHP class names are not. This could language that allow traditional OO 06 } cause missing classes to try and load design patterns to be used natively 07 non-existent files from disk. Porting code within PHP. These were possible previ- 08 function __set($variable_U from a Windows environment will often ously, albeit with some minor code name, $value) include at least one of this variety! hacks. The second involves new features 09 { that haven’t been technically possible 10 print "I can't set the U The Girl in the Other Room before, because of the language design.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages6 Page
-
File Size-