|
PHP 5, Oracle, and the Future by Andi Gutmans
Get an overview of the some of the new features in PHP 5 and its future by PHP 5's release manager
PHP 5 (PHP: Hypertext Preprocessor Version 5) was officially released on July 13, 2004. Not surprising, the release was widely covered by the media due to the leadership role PHP plays in the Web application market. It is true that technologies such as .NET and J2EE have had more exposure and hype than PHP, but ease-of-use, performance, tight integration with the Apache Web server, and a large collection of application building blocks have led PHP to be the leading Web application development language.
You might ask yourself, since PHP 4 featuring the Zend Engine I was so successful, why do we even need PHP 5 and the Zend Engine II? The truth is that there were certain areas in which PHP 4 did not excel. Most of these areas were more important for large projects and companies, where project management is more structured and interoperability between systems is a must. PHP 5 addresses these issues, allowing PHP not only to be more attractive for such projects but also to remain the leading technology for Web application development.
In this article I cover:
- The reasoning behind PHP 5
- A short overview of some of the new features
- A brief look at the future for PHP and Oracle users
The New Object-Oriented Model of the Zend Engine II
Background. With PHP's adoption growing steadily, its use in larger projects is also constantly increasing. There does seem to be a connection between large projects and the use of object-oriented (OO) methodology. Not that you can't write a small OO application, and it is certainly possible to write large, impressive applications without OOP (Object Oriented Programming); however, there does seem to be a tendency to pick the object-oriented paradigm in these cases. It is probably mainly due to OOP having more conventional tools for functional and technical design (UML — Unified Modeling Language), reuse of solutions for recurring problems (design patterns), and built-in mechanisms in the OO languages themselves that help enforce software designs and contracts.
The main problem with PHP's object model in prior versions was that objects were implemented as native types with copy-semantics similar to integers and strings. This not only led to some very confusing behavior, due to sometimes unexpected implicit object cloning by PHP, but it also didn't allow us to implement some basic features, such as the ability to de-reference objects that are returned from methods.
The following examples illustrate these two problems. a) Implicit object cloning:
<?php
class Person {
var $name;
function Person($name) {
$this->name = $name;
}
function setName($name) {
$this->name = $name;
}
function getName() {
return $this->name;
}
}
function lowerCaseName($obj)
{
$new_name = strtolower($obj->getName());
$obj->setName($new_name);
}
$obj = new Person("Andi");
lowerCaseName($obj);
print $obj->getName();
?>
Most developers would expect this example to print out "andi" However, surprisingly, this example prints out "Andi" in PHP 4. This is due to the previously mentioned way PHP 4 treats objects like regular native types, and as a result, passing $obj to lowerCaseName() by-value, actually clones the object. The resulting manipulation that lowerCaseName() performs on $obj is done on a cloned version of the object. This behavior not only leads to surprising results but, for developers who were aware of this problem, it would require passing and returning objects by-reference, which would make the code harder to maintain because they'd have to insert & signs in many places (passing by-reference, returning by-reference, and assigning by-reference).
b) Inability to de-reference objects returned from methods:
$obj->getParentObject()->method();
If you aren't very familiar with PHP 4, you would probably expect this example to work. However, as a result of the before-mentioned implicit cloning, the ability to de-reference an object that is returned from a method did not exist and could not be implemented. As a workaround, a lot of PHP 4 code would look as follows:
[MySql]PHP存取 Mysql 数据乱码终极解决方案 [Web开发]PHP提示Notice: Undefined variable的解决办法 [Web开发]PHP 大小写函数 [Web开发]PHP的sleep函数关闭窗口后是否继续运行? [Web开发]教你如何在PHP开启gzip页面压缩实例介绍 [Web开发]PHP过滤HTML字符串的常用函数使用方法介绍 [Web开发]PHP采集程序常用函数大全 [Web开发]用PHP实现Javascript的escape(),unescape()的方法 [Web开发]常见的PHP截取字符串函数整理 [Web开发]VS2005+SQL2005之.NET2.0数据库连接
|