
| The future of PHP | ||||||||||||||||||||||||||||||||||
| 摘自: IBM developerWorks Worldwide 被阅读次数: 26 | ||||||||||||||||||||||||||||||||||
由 yangyi 于 2008-05-09 23:32:13 提供 | ||||||||||||||||||||||||||||||||||
Level: Intermediate Nathan A. Good (mail@nathanagood.com), Senior Information Engineer, Consultant 06 May 2008 PHP's next edition, V6, includes new features and syntax improvements that will make it easier to use from an object-oriented standpoint. Other important features, such as Unicode support in many of the core functions, mean that PHP V6 is positioned for better international support and robustness. PHP is already popular, used in millions of domains (according to Netcraft), supported by most ISPs and used by household-name Web companies like Yahoo! The upcoming versions of PHP aim to add to this success by introducing new features that make PHP more usable in some cases and more secure in others. Are you ready for PHP V6? If you were upgrading tomorrow, would your scripts execute just fine or would you have work to do? This article focuses on the changes for PHP V6 — some of them back-ported to versions PHP V5.x — that could require some tweaks to your current scripts. If you're not using PHP yet and have been thinking about it, take a look at its latest features. These features, from Unicode to core support for XML, make it even easier for you to write feature-filled PHP applications. PHP V6 is currently available as a developer snapshot, so you can download and try out many of the features and changes listed in this article. For features that have been implemented in the current snapshot, see Resources. Much improved for PHP V6 is support for Unicode strings in many of the core functions. This new feature has a big impact because it will allow PHP to support a broader set of characters for international support. So, if you're a developer or architect using a different language, such as the Java™ programming language, because it has better internationalization (i18n) support than PHP, it'll be time to take another look at PHP when the support improves. Because you can download and use a developer's version of PHP V6 today, you will see some functions already supporting Unicode strings. For a list of functions that have been tested and verified to handle Unicode, see Resources.
Namespaces are a way of avoiding name collisions between functions and classes without using prefixes in naming conventions that make the names of your methods and classes unreadable. So by using namespaces, you can have class names that someone else might use, but now you don't have to worry about running into any problems. Listing 1 provides an example of a namespace in PHP. You won't have to update or change anything in your code because any PHP code you write that doesn't include namespaces will run just fine. Because the namespaces feature appears to be back-ported to V5.3 of PHP, when it becomes available, you can start to introduce namespaces into your own PHP applications. Listing 1. Example of a namespace
Depending on how you use PHP and what your scripts look like now, the language and syntax differences in PHP V6 may or may not affect you as much as the next features, which are those that directly allow you to introduce Web 2.0 features into your PHP application. SOAP is one of the protocols that Web services "speak" and is supported in quite a few other languages, such as the Java programming language and Microsoft® .NET. Although there are other ways to consume and expose Web services, such as Representational State Transfer (REST), SOAP remains a common way of allowing different platforms to have interoperability. In addition to SOAP modules in the PHP Extension and Application Repository (PEAR) library, a SOAP extension to PHP was introduced in V5. This extension wasn't enabled by default, so you have to enable the extension or hope your ISP did. In addition, PEAR packages are available that allow you to build SOAP clients and servers, such as the SOAP package. Unless you change the default, the SOAP extension will be enabled for you in V6. These extensions provide an easy way to implement SOAP clients and SOAP servers, allowing you to build PHP applications that consume and provide Web services. If SOAP extensions are on by default, that means you won't have to configure them in PHP. If you develop PHP applications and publish them to an ISP, you may need to check with your ISP to verify that SOAP extensions will be enabled for you when they upgrade. As of PHP V5.1, XMLReader and XMLWriter have been part of the core of PHP, which makes it easier for you to work with XML in your PHP applications. Like the SOAP extensions, this can be good news if you use SOAP or XML because PHP V6 will be a better fit for you than V4 out of the box. The XMLWriter and XMLReader are stream-based object-oriented classes that allow you to read and write XML without having to worry about the XML details.
In addition to having new features, PHP V6 will not have some other functions and
features that have been in previous versions. Most of these things, such as Features that will be removed from the PHP version include:
Citing portability, performance, and inconvenience, the PHP documentation discourages
the use of Listing 2. Using magic_quotes (discouraged)
After preparing your PHP code for the new versions of PHP, your code should look like that in Listing 3. Listing 3. Using parameterized queries (recommended)
Now that support for The Listing 4. Using register_globals (discouraged)
If your PHP code uses global variables, you should update it. If you don't update your code to get prepared for newer versions of PHP, consider updating it for security reasons. When you're finished, your code should look like Listing 5. Listing 5. Being specific instead (recommended)
The Listing 6. Using deprecated registered arrays (discouraged)
If your PHP code looks like that shown in Listing 6, update it to look like that in
Listing 7. Shut off the Listing 7. Using $_GET (recommended)
The Microsoft Active Server Pages (ASP)-style tags — the shorter version of the PHP
tags — are no longer supported. To make sure this is not an issue for your
scripts, verify that you aren't using the The PHP team is removing support for both FreeType 1 and GD 1, citing the age and lack of ongoing developments of both libraries as the reason. Newer versions of both of these libraries are available that provide better functionality. For more information about FreeType and GD, see Resources. The Table 1. ereg() functions and their PCRE equivalents
Some of the features mentioned here have also been ported to PHP V5.3, which is scheduled to be released during the first quarter of 2008. You may want to upgrade to V5.3 and start using these features now, so that when you move to V6 of PHP, it'll be less of a jump. The following list of features have been back-ported to V5.3:
PHP V6 will offer many improvements and will clean up some of the functionality that has been in older versions of PHP. To take advantage of the new features and cleanup, read through the NEWS list (see Resources), as it will contain the most up-to-date information about what is included (or not included) in PHP V6. You can download developer versions of PHP V6 today and start making sure that your applications are unaffected by the changes. You can also take this opportunity to clean up your own scripts, removing any of the deprecated functions mentioned in this article or updating your syntax to make sure that your applications are supported. Learn
Get products and technologies
Discuss
Original link: http://www.ibm.com/developerwork... | ||||||||||||||||||||||||||||||||||