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
<?php
// I\'m not sure why I would implement my own XMLWriter, but at least
// the name of this one won\'t collide with the one built in to PHP
namespace NathanAGood;
class XMLWriter
{
// Implementation here...
}
$writer = new NathanAGood::XMLWriter();
?>
|
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 register_globals and safe_mode, are widely considered \"broken\" in current PHP, as they may expose security risks. In an effort to clean up PHP, the functions and features listed in the next section will be removed, or deprecated, from PHP. Opponents of this removal will most likely cite issues with existing scripts breaking after ISPs or enterprises upgrade to PHP V6, but proponents of this cleanup effort will be happy that the PHP team is sewing up some holes and providing a cleaner, safer implementation.
Features that will be removed from the PHP version include:
- magic_quotes
- register_globals
- register_long_arrays
- safe_mode
PHP的下一个版本,V6,包含了很的新特性和语法改进,会使它在面向对象方面性更易用。其他重要的特性:比如在核心函数中对Unicode (统一编码)的支持,这意味着 PHP 6提供了更好的更可靠国际支持。
PHP已经很流行,被无数的站点使用,被大部分因特网接入商所支持,被Yahoo这样的大网络公司使用着。在即将来临的PHP版本中准备增加一些成功的新特性,使PHP在某些场合下更易用更安全。你准备好接受 PHP 6 了吗?如果你明天就升级了,你的程序会运行得很好吗?你该怎么办?这篇文章集合了PHP 6的改变,他们中的一些备份移植到版本的PHP v5.x,您目前的脚本可能需要进行一些调整。
如果你现在使用不是PHP,但是一直在考虑它,考虑一下它的新特性。这些特点,从Unicode的核心支持到XML支持,使它更容易为你写的功能填补PHP的应用。
PHP 6 新特性
PHP 6当前已经作为开发者快照使用,所以你可以下载和试用一下这篇文章列出很多特性,这些特性已经在当前的快照中实现了。见资源。
改进 Unicode 支持
在PHP的核心函数中,有很多对Unicode 字符串的支持的改进,这些新特性将产生巨大的影响因为它允许PHP为国际字符提供更多的支持。所以如果一个开发者或者架构师使用不同的语言,例如Java程序语言,是因为它具有超过PHP的国际化支持的话,当支持改进时他会花一点时间来考虑一下PHP。
因为今天你已经可以下载到开发者版本的 PHP V6,你将看到一些功能函数已经支持Unicode字符串。有一个函数清单已经被测试和验证了完全可以处理Unicode,参见资源。
命名空间
命名空间是一种避免因函数或者类之间的命名冲突而使你的函数和类以及方法无法读取,而不使用前缀命名惯例的一种方法。因此,通过使用命名空间,你可以命名别人可能已经使用的类名,而不用担心在运行时会出错。表一提供了一个在PHP中使用命名空间的示例。
您不用在源代码中做更新或更改,因为你写的任何PHP代码可以不包含命名空间而运行得很好。因为命名空间特性似乎会移植到PHP 5.3 X中,如果它可以使用,您可以在自己的程序中引用命名空间。
表一,命名空间示例
<?php
// I'm not sure why I would implement my own XMLWriter, but at least
// the name of this one won't collide with the one built in to PHP
namespace NathanAGood;
class XMLWriter
{
// Implementation here...
}
$writer = new NathanAGood::XMLWriter();
?>
Web 2.0 特性
依赖于你怎么使用PHP和你现在脚本的是什么样子的,现在的语言和语法差异,可能会或者不会最大程度的影响下面一些特性,这是指那些直接让你引用的Web 2.0功能到你的PHP应用程序。
SOAP
SOAP是一种网络服务“说话”的协议,并且支持不少其他语言,例如Java和微软的.NET,虽然有其他的方法来驱动和使用网络服务,比如 表象化状态转变(Representational State Transfer )REST,SOAP仍然在使不同平台具有可操作性中是最常用的。此外,SOAP在PHP扩展和PEAR库中使用,SOAP在PHP中默认是不支持的,因此你启用这个扩展或者叫你的ISP启用。此外,PEAR包允许你建立SOAP客户端和服务器,如SOAP包。
如果你改变了默认设置,SOAP将会在PHP 6中启用。这个扩展将提供你很容易的的实现SOAP客户端和SOAP服务,允许你编写的应用提供使用或者网络服务。
如果SOAP扩展是默认设置,那就意味着你不能在PHP中设置它们,如果您开发的PHP应用程序并且它们发布到一个ISP服务器上,您可能需要检查一下你的ISP,以验证SOAP并启用为他们升级。
在PHP 5.1中XMLReader 和XMLWriter已经变成PHP核心的一部分,这使你工作起来更轻松如果在你的PHP程序中需要使用到XML的话。和SOAP扩展一样,如果你使用SOAP或者XML这是个好消息因为PHP 6比已经出炉的PHP4 更适合你。
被删除的东西
除了具有的一些新功能,PHP 6引擎将删除一些在前面版本中已经有的功能。大部分这些功能,如register_globals 和safe_mode 在目前的PHP中被视为“破的”。因为他们可能会暴露一些安全风险。PHP在努力的清除中,在下一个版本中这些将从PHP中删除或者废弃。反对者认为大部分ISP或者企业会保留现在的脚本因为升级到PHP6会破坏现在的的脚本,但是支持者认为很高兴看到PHP团队修补了这些漏洞,并且提供了一个干净,安全的运行工具。
将从PHP删除的功能有:
magic_quotes register_globals register_long_arrays safe_mode
更详细情况请看这里:IBM 社区
译者Blog:Open ABC
-
25个顶级PHP模板引擎
为了找到一个好的模板引擎,我在互联网上进行搜索,目前已经整理出了以下名单: Smarty Smarty的特点是将模板编译成PHP脚本,然后执行这些脚本。很快,非常灵活。 Heyes Template...
-
优化PHP代码的40条建议
英文版权归Reinhold Weber所有,中译文作者yangyang(aka davidkoree)。双语版可用于非商业传播,但须注明英文版作者、版权信息,以及中译文作者。翻译水平有限,请广大PHP...
-
所有PHP程序员都应该知道的五个工具
在参与了几个大型PHP项目,写了很多PHP代码以后,我发现很多工具可以提高代码质量,简化发布,使得做为PHP开发人员的生涯变得轻松许多。许多这样的工具可能已经为大家所用。但是,由于一些人甚至没有注意到...
-
加速PHP应用 - 用Xdebug分析你的代码
面向对象编程越来越流行了,在PHP领域也不例外。所以你选择了合适的设计模式,在最新的framework上开发你的网站,抽象你的数据库访问以至于你都忘了SQL这种东西了。 接下来是什么呢? 当你开始转...
-
40个迹象表明你还是PHP菜鸟
英文版权归Reinhold Weber所有,中译文作者yangyang(aka davidkoree)。双语版可用于非商业传播,但须注明英文版作者、版权信息,以及中译文作者。翻译水平有限,请广大P...
-
在AMP环境中使用GWT
1. 简介 1.1 前言 写下这篇文章是因为考虑到有些用户希望在AMP(Apache,MySQL,PHP)环境中使用GWT(Google Web Toolkit)开发动态应用程序。基本想法是写一个非...
-
CakePHP 简明指南
Cakephp 简明指南
-
PHP测试驱动开发介绍
PHP测试驱动开发介绍 摘要本文向你介绍测试驱动开发的概念,并用一个简单的示例项目来做示范。 介绍 开发PHP产品有很多不同的方法。我们大多数倾向于从一个简单的脚本开始,逐步向前推进。 或许我们...
相关小组
标签:

PHP 6 的新特性
翻译: