仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 2256|回复: 19
打印 上一主题 下一主题

[学习教程] PHP教程之Whats New in PHP 5 countstars(翻译)...

[复制链接]
变相怪杰 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-2-4 00:29:46 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
在我开始学习PHP以前,我从未想过要做软件工程,即便是在去听过华育国际的关于软件工程的美好前景后,因为我一直都没有想过要与代码打交道,而是想学好所学专业,做个网络工程师或者是网络安全人员。   翻译:深空
作者:Andi Gutmans, Stig Bakken, and Derick Rethans
不得私自转载。

Introduction [绪论]
Language Features [言语特征]
• New Object Oriented model [新的面向对象模子]
• New Object Oriented Features [新的面向对象特征]
• Other New Language Features [其他新的言语特征]
General PHP changes [PHP 变更概要]
• XML and Web Services [XML 和 Web 办事器]
• New MySQLi (MySQL Improved) extension [新的 MySQLi (改进的 MySQL) 扩大
]
• SQLite extension [SQLite 扩大]
• Tidy extension [Tidy 扩大]
• Perl extension [Perl 扩大]
• Other New Things in PHP 5 [其他 PHP5 新事物]
Summary [总结]




The best way to be ready for the future is to invent it. (John Sculley)
为将来作好筹办的最好办法就是发明它。 (John Sculley)

Introduction [绪论]
Only time will tell if the PHP 5 release will be as successful as the releases
of its two predecessors (PHP 3 and PHP 4). The new features and changes aim t
o rid PHP of any weaknesses it may have had and make sure that it stays in the
lead as the best web scripting language on the globe.
只要工夫可以证实 PHP5 是不是和他的两个先辈(PHP3 和 PHP4)一样胜利。新的言语特征和
改动的目标是为了消弭 PHP 能够已具有的弱点, 和证明它作为全球最优异的网页剧本
言语所处的抢先位置。

This book covers PHP 5 and its new features in great detail. However, for thos
e of you familiar with PHP 4, and are eager to know what is new in PHP 5, then
this chapter is for you.
这本书包括了 PHP5 和它的新特征的具体描写。但是,作为 PHP4 的密切密友的你都巴望
晓得 PHP5 事实做了哪些更新,那末,这一章就是为你筹办的。

The chapter will cover:
本章将包含:

The new language features [新的言语特征]
News concerning PHP extensions [关于 PHP 扩大的新动静]
Other noteworthy changes [其他值得注重的改动]

Language Features [言语特征]
New Object Oriented model [新的面向对象模子]
When Zeev Suraski added the object-oriented syntax back in the days of PHP 3,
it was added as "syntactic sugar for accessing collections". The object-orient
ed model also had support for inheritance and allowed a class (and object) to
aggregate both methods and properties, but not much more. When Zeev and Andi r
ewrote the scripting engine for PHP 4, it was a completely new engine, running
much faster, much more stable and with many more features. However, the objec
t-oriented model first introduced in PHP 3, was barely touched.
当 Zeev Suraski 在 PHP3 时代添加面向对象语法的时分,它被作为 "syntactic sugar
for accessing collections" 添加。该面向对象模子也撑持承继和答应类(或对象)聚合
办法和属性,但没有更多的特征了。当 Zeev 和 Andi 为 PHP4 重写剧本引擎的时分,它
是一个完整新的引擎,运转更快、更不乱,和纠合了更多的特征。但是,面向对象模子首
次在 PHP3 中引入,却少少触及。

Although the object model had serious limitations it was used extensively arou
nd the world, often in very large PHP applications. This impressive use of the
OOP paradigm with PHP 4 despite its weaknesses led to it being the main focus
for the PHP 5 release.
固然,对象模子已严重限制了它活着界局限上的普遍利用--经常长短常大型的 PHP 应
用法式,然而这个给人印象深入的面向对象法式设计典范的使用和 PHP4 的弱点招致它成
为 PHP5 宣布版本的次要核心。

So what were some of the limitations in PHP 3 & 4? The biggest limitation (whi
ch led to further limitations) was the fact that the copy semantics of objects
were the same as for native types. So how did this actually affect the PHP de
veloper? When you’d assign a variable (that points to an object) to another v
ariable, a copy of the object would be created. Not only did this impact perfo
rmance but it usually also lead to obscure behavior and bugs in PHP 4 applicat
ions because many developers thought that both variables would be pointing at
the same object which wasn’t the case. They were pointing at separate copies
of the same object, changing one would not change the other.
那末,PHP3 & PHP4 的局限性在哪里呢?最大的局限性(这招致更大的局限)是,现实上
对象的拷贝和原始对象一样,因而这实践上影响了 PHP 的开辟。当你将一个变量(它指向
一个对象)赋值给别的一个变量的时分,这个对象的一个拷贝将被创立。在 PHP4 的使用
法式里如许做不但对履行发生影响,并且凡是招致恍惚的行动和毛病。由于很多开辟者认
为这两个变量指向不异的对象(现实其实不如斯)。它们分离指向了这个对象的两个拷贝,
改动个中一个其实不能改动别的一个。

For example [好比]:

class Person {
var $name;
function getName() {
return $this->name;
}
function setName($name) {
$this->name = $name;
}
function Person($name) {
$this->setName($name);
}
}

function changeName($person, $name) {
$person->setName($name);
}

$person = new Person("Andi");
changeName($person, "Stig");
print $person->getName();

In PHP 4, this piece of code would print out "Andi". The reason is that we pas
s the object $person to the changeName() function by-value, and thus, $person
is copied and changeName() works on a copy of $person.
在 PHP4 中,这段代码将打印 "Andi" 。缘由是咱们经由过程值将对象 $person 传递给函数
changeName(),那末,$person 的一个拷贝被创立,而 changeName() 运转了 $person 的
这个拷贝。

This behavior is not very intuitive, as many developers would expect the Java-
like behavior. In Java variables actually hold a handle (or pointers) to the o
bject, and therefore, when it is copied only the handle and not the entire obj
ect is duplicated.
这类行动其实不直不雅,良多开辟者原本都觉得它会像 Java 的体例一样运转。在 Java 里,
变量实践上坚持了对象的一个句柄(或称唆使器),因而它仅仅是作为一个句柄而不是
全体被拷贝出来
There were two kinds of users in PHP 4, the ones who were aware of this proble
m and the ones who weren’t. The latter would usually not notice this problem
and their code was written in a way where it didn’t really matter if the prob
lem existed or not. Surely some of these people had sleepless nights trying to
track down weird bugs which they couldn’t pinpoint. The former group dealt w
ith this problem by always passing and assigning objects by reference. This wo
uld prevent the engine from copying their objects but would be quite a headach
e as the code included numerous ‘&’ signs.
PHP4 有两种分歧类型的用户,一种晓得这个成绩而另外一种却不晓得。后者凡是没有注重到
这个成绩,这个成绩是不是存在关于他们写的代码来讲没有多大关系。切实其实,这类人中的一
些人,凡是整夜追捕那些他们不克不及肯定的稀里糊涂的毛病。曩昔的团队凡是经由过程给这个对
象注册一个援用来处置这个成绩。这将避免引擎创立对象的拷贝,然而有摇头痛的是代码
中包括了浩瀚的 ‘&’ 标签。

The old object model not only led to the above-mentioned problems but also led
to fundamental problems that prevented implementing some additional features
on top of the existing object model.
旧的对象模子不单单招致下面说起的成绩,并且障碍了在这个已存在的对象模子上完成
一些附加的特征。

In PHP 5, the infrastructure of the object model was rewritten to work with ob
ject handles. Unless you explicitly clone an object by using the clone keyword
you will never create behind the scene duplicates of your objects. In PHP 5,
there is neither a need to pass objects by reference nor assigning them by ref
erence.
在 PHP5 中,重写了对象模子的布局使它以对象句柄运转。除非你利用 clone 关头字切实
地克隆了一个对象不然你基本不克不及创立对象的拷贝。在 PHP5 中,不需求传递对象的援用
或注册对象的援用。

Note: Passing by reference and assigning by reference is still supported, in c
ase you want to actually change a variable’s content (whether object or other
type).
注重:传递援用和注册援用依然被撑持,万一你要改动一个变量的内容(不论是对象或
其他类型)。

New Object Oriented Features [新的面向对象特征]
The new object oriented features are too numerous to give a detailed descripti
on in this section. The object oriented language chapter goes over each featur
e in detail.
新的面向对象特征其实太多了,不克不及在这一章节里具体论述,面向对象言语章节将具体阐
述每个特征。

The following is a list of the main new features:
上面是次要的新特征列表:

1. public/private/protected access modifiers for methods and properties
1. 为办法和属性添加了 公共的/公有的/回护的 会见权限润色
Allows the use of common OO access modifiers to control access to methods and
properties.
答应利用公共的面向对象会见权限润色来掌握办法和属性的利用权限。

class MyClass {
private $id = 18;

public function getId() {
return $this->id;
}
}

2. Unified constructor name __construct()
2. 一致的机关器名: __construct()
Instead of the constructor being the name of the class, it should now be decla
red as __construct(), making it easier to shift classes inside class hierarchi
es.
取代了利用类名作为类的机关器的称号,它如今应当被声明为 __construct(),创立它比
在类的条理上交换类更轻易。

class MyClass {
function __construct() {
print "Inside constructor";
}
}

3. Object destructor support by defining a __destructor() method
3. 对象析构函数经由过程界说 __destructor() 办法失掉撑持
Allows defining a destructor function that runs when an object is destroyed.

答应界说一个析构函数当对象溃散的时分运转。

<?
class MyClass {
function __destruct() {
print "Destroying object";
}
}
?>

4. Interfaces
4. 接口
Gives the ability for a class to fulfill more than one is-a relationships. A c
lass can inherit from one class only but may implement as many interfaces as i
t wants.
付与类具有更多的互相关系。一个类只能从别的一个类中承继然而可以完成更多的想要的
接口。

interface Display {
function display();
}

class Circle implements Display {
function display() {
print "Displaying circle ";
}
}

5. instanceof operator
5. 实例操作
Language level support for is-a relationship checking. The PHP 4 is_a() functi
on is now deprecated.
供应 is-a 言语级其余反省撑持,PHP4 中的 is_a() 函数如今不同意利用。

if ($obj instance of Circle) {
print '$obj is a Circle';
}

6. final methods
6. final 办法
The final keyword allows you to mark methods so that an inheriting class can't
overload them.
final 关头字答应你标志办法,使得承继类不克不及载入它们。

class MyClass {
final function getBaseClassName() {
return __CLASS__;
}
}

7. final classes
7. final 类
After declaring a class as final, it can’t be inherited. The following exampl
e would error out:
在声明一个 final 类以后它们不克不及被承继,上面的例子将发生毛病:

final class FinalClass {
}

class BogusClass extends FinalClass {
}

8. Explicit object cloning
8. 明白的对象克隆
In order to clone an object you have to use the clone keyword. You may declare
a __clone() method which will be called during the clone process (after the p
roperties have been copied from the original object).
为了复制一个对象你必需利用 clone 关头字。你可以声明一个 __clone() 办法,当一个
类被拷贝的时分它将履行(在原对象属性被拷贝以后)。

class MyClass {
function __clone() {
print "Object is being cloned";
}
}
$obj = new MyClass();
clone $obj;

9. Class constants
9. 类常量
Classes definitions can now include constant values, and are referenced using
the class.
类界说如今包括了常量界说,而且经由过程类来援用它们。

class MyClass {
const SUCCESS = "Success";
const FAILURE = "Failure";
}
print MyClass::SUCCESS;

10. Static members
10. 静态成员
Classes definitions can now include static members (properties), accessible vi
a the class. Common usage of static members is in the Singleton pattern.
类界说如今包括了静态成员(属性)的界说,并经由过程类会见它们。凡是静态成员用于独自
的局部。

class Singleton {
static private $instance = NULL;

private function __construct() {
}

static public function getInstance() {
if (self::$instance == NULL) {
self::$instance = new Singleton();
}
return self::$instance;
}
}

11. Static methods
11. 静态办法
You can now define methods as static allowing them to be called from non-objec
t context. Static methods don’t define the $this variable as they aren’t bou
nd to any specific object.
你如今可以界说一个静态的办法,而且可以在没有对象的局限内被挪用。静态办法没有定
义 $this 变量作为其他特定对象的限制。

<?
class MyClass {
static function helloWorld() {
print "Hello, world";
}
}
MyClass::helloWorld();
?>

12. abstract classes
12. 笼统类
A class may be declared as abstract so as to prevent it from being instantiate
d. However, you may inherit from an abstract class.
类可使用 abstract 声明避免它们被实例化。但是,你可以承继一个笼统类。

abstract class MyBaseClass {
function display() {
print "Default display routine being called";
}
}

13. abstract methods
13. 笼统办法
A method may be declared as abstract, thereby deferring its definition to an i
nheriting class. A class that includes abstract methods must be declared as ab
stract.
办法可使用 abstract 声明,因而,从一个承继类延续他们的界说。一个类假如包括一
个笼统办法必需用 abstract 声明。

abstract class MyBaseClass {
abstract function display();
}

14. Class type hints
14. 类类型提醒
Function declarations may include class type hints for their parameters. If th
e functions are called with an incorrect class type an error occurs.
函数声明可以包括类类星体是作为他们的参数,假如一个函数被一个毛病的类挪用将打印
一个毛病。

function expectsMyClass(MyClass $obj) {

}

15. Support for dereferencing objects which are returned from methods.
15. 撑持从办法中前往非联系关系对象
In PHP 4, you could not directly dereference objects which are returned from m
ethods. You would have to first assign the object to a dummy variable and then
dereference it.
在 PHP4 中,你不克不及直接从一个办法中前往的对象中解析,你必需将这个对象注册给一个
两头变量,然后解析它。
PHP 4:

$dummy = $obj->method();
$dummy->method2();

PHP 5:

$obj->method()->method2();

16. Iterators
16. 迭代
PHP 5 allows both PHP classes and PHP extension classes to implement an Iterat
or interface. Once you implement this interface you will be able to iterate in
stances of the class by using the foreach() language construct.
PHP5 答应 PHP 类和 PHP 扩大类履行一个迭代接口。一旦你履行这个接口,已将可以经由过程
利用 foreach() 言语布局重复实例化这个类。

$obj = new MyIteratorImplementation();
foreach ($obj as $value) {
print "$value";
}

For a more complete example, please refer to the "Advanced OOP & Design Patter
ns" chapter.
检查一个更加完全的例子,请查阅“初级面向对象和设计模子”这一章节。

17. __autoload()
17. __autoload()
Many developers writing object-oriented applications create one PHP source fil
e per-class definition. One of the biggest annoyances is having to write a lon
g list of needed includes at the beginning of each script (one for each class)
. In PHP 5, this is no longer necessary. You may define an __autoload() functi
on which is automatically called in case you are trying to use a class which h
asn’t been defined yet. By calling this function the scripting engine is givi
ng a last chance to load the class before PHP bails out with an error.
很多开辟人员在写一个面向对象使用法式的时分,为每一个类嘉奖以俄国 PHP 文件,个中一
个最大的懊恼是,在每个剧本的入手下手局部都要写一个很长的文件包括列表(一个类包括
一次)。在 PHP5 中,这需求在这么做了。你可以界说一个 __autoload() 函数,它将自
动挪用一个还没有被界说的类。经由过程挪用这个函数,剧本引擎将在 PHP 抛出一个毛病之前
一向延续测验考试读取这个类。

function __autoload($class_name) {
include_once($class_name . "php");
}

$obj = new MyClass1();
$obj2 = new MyClass2();

Other New Language Features [其他新的言语特征]
1. Exception handling
1. 异常处置
PHP 5 adds the ability for the well known try/throw/catch structured exception
handling paradigm. You are only allowed to throw objects which inherit from t
he Exception class.
PHP5 添加了一个知名的 try/throw/catch 异常处置系统。仅答应你抛出一个承继自一个
呈现成绩的类的对象。

class SQLException extends Exception {
public $problem;
function __construct($problem) {
$this->problem = $problem;
}
}

try {
...
throw new SQLException("Couldn’t connect to database");
...
} catch (SQLException $e) {
print "Caught an SQLException with problem $obj->problem";
} catch (Exception $e) {
print "Caught unrecognized exception";
}

Currently for backwards compatibility purposes most internal functions do not
throw exceptions. However, new extensions are making use of this capability an
d you can use it in your own source code. Also, similar to the already existin
g set_error_handler() you may use set_exception_handler() to catch an unhandle
d exception before the script terminates.
如今,为了向后兼容,绝大局部外部函数不会抛出异常。但是,为了利用这些功效,新的
扩大正在被制订,你可以在本人的代码里利用它们。并且,和已存在的 set_error_han
dler() 相似,你可以在剧本终止前利用 set_exception_handler() 来捕捉一个未经处置
过的异常。

2. foreach with references
2. foreach 与援用
In PHP 4, you could not iterate through an array and modify its values. PHP 5
supports this by allowing you to mark the foreach() loop with the ‘&’ (refer
ence) sign, thus, making any values you change affect the array you’re iterat
ing over.
在 PHP4 里,你不克不及迭代一个数组和改动它们的值。PHP5 答应你经由过程利用‘&’(援用)
标志 foreach() 轮回来完成,创立任何你改动的值影响你所迭代的数组。

foreach ($array as &$value) {
if ($value === "NULL") {
$value = NULL;
}
}

3. default values for by-reference parameters
3. 经由过程援用的参数的默许值
In PHP 4, default values could only be given to parameters which are passed by
-value. Giving default values to by-reference parameters is now supported.
在 PHP4 中,参数只能经由过程值来吸收默许值。如今给参数一个援用的值作为值失掉撑持。


function my_func(&$arg = null) {
if ($arg === NULL) {
print '$arg is empty';
}
}
my_func();

General PHP changes [PHP 变更概要]
XML and Web Services [XML 和 Web 办事器]
Following the changes in the language, the XML updates in PHP 5 are most proba
bly the most significant and exciting. The enhanced XML functionality in PHP 5
puts it on par with other web technologies in some areas and overtakes them i
n others.
跟着言语中的改动,XML 在 PHP5 中的更新也许最为主要和冲动人心。PHP5 中加强的 XM
L 函数和不异范畴里的其他 Web 手艺一样,并且超越它们中的一局部。

The Foundation [基本]
XML support in PHP 4 was implemented using a variety of underlying XML librari
es. SAX support was implemented using the old Expat library, XSLT was implemen
ted using the Sablotron library (or using libxml2 via the DOM extension) and D
OM was implemented using the more powerful libxml2 library by the GNOME projec
t.
XML 在 PHP4 中经由过程底层的 XML 库失掉撑持;SAX 经由过程旧的 Expat 库失掉撑持;XSLT 通
过 Sablotron 库(或经由过程 DOM 扩大利用 libxml2)失掉撑持;而 DOM 经由过程利用加倍强
大的 GHOME 项目标 libxml2 库失掉撑持。

Using a variety of libraries did not make PHP 4 excel when it came to XML supp
ort. Maintenance was poor, new XML standards weren’t always supported, perfor
mance wasn’t as good as it could have been, and interoperability between the
varies XML extensions did not exist.
利用这类种库并没有使 PHP4 在 XML 撑持上优于别人。可保护性差,新的 XML 尺度不总
是被撑持,功能不睬想,和在这些扩大之间没有兼容性可言。

In PHP 5, all XML extensions have been rewritten to use the superb libxml2 XML
toolkit (http://www.xmlsoft.org/
. It is a very feature rich, highly maintain
ed and efficient implementation of the XML standards bringing the cutting edge
of XML technology to PHP.
在 PHP5 中,一切的 XML 扩大已被重写并利用优异的 libxml2 XML 东西包(http://ww

w.xmlsoft.org/)。它具有十分丰厚的特征。及洼地坚持和无效地完成 XML 尺度为 PHP 带
来了 XML 的优势。
All the above mentioned extensions (SAX, DOM and XSLT) now use libxml2 includi
ng the new additional extensions SimpleXML and SOAP.
一切下面说起的这些扩大 (SAX, DOM 和 XSLT) 如今利用 libxml2 --包括新的附加扩大
SimpleXML 和 SOAP。

SAX
As mentioned, the new SAX implementation has switched from using Expat to libx
ml2. Although the new extension should be compatible there may be some small s
ubtle differences. Developers who still want to work with the Expat library ca
n do so by configuring and building PHP accordingly (not recommended).
提起它,新的 SAX 的完成已从 Expat 转到了 libxml2。固然新的扩大在兼容性方面可
能存在一些纤细的不同。开辟者依然可以经由过程设置装备摆设 PHP 来完成 Expat 扩大的撑持(这并
不被保举)。

DOM
Although DOM support in PHP 4 was also based on the libxml2 library, it was qu
ite buggy, had memory leaks and the API in many cases was not W3C compliant. T
he DOM extension went through a thorough facelift for PHP 5. Not only was the
extension mostly rewritten it is now also W3C complaint. For example, function
names now use studlyCaps as described by the W3C standard making it easier fo
r you to read general W3C documentation and implementing what you learnt, righ
t away in PHP. In addition, the DOM extension now supports three kinds of sche
mas for XML validation, DTD, XML Schema and RelaxNG.
固然 DOM 撑持在 PHP4 中依然是基于 libxml2 的,然而它破绽百出,存在着一个内存漏
洞和因为多种缘由 API 并非允从于 W3C。DOM 扩大为 PHP5 做了完全的改善,不单单几
乎完整重写,并且如今也是 W3C 建议。好比,函数名如今经由过程 W3C 尺度利用 studlyCap
s 作为描写,使得你在 PHP 中更轻易浏览整体的 W3C 文档,和履行你所学到的器材。


As a result of these changes PHP 4 code using DOM will not always run in PHP 5
. However, in most cases adjusting the function names to the new standard will
probably do the trick.
因为这些改动的缘由,PHP4 中利用 DOM 的代码将不成能老是在 PHP5 中可用。但是,在
大多半场所下,调剂函数名到新的尺度多是个办法。

XSLT
In PHP 4, there were two extensions that supported XSL Transformations. The fi
rst was using the Sablotron extension and the second was using the XSLT suppor
t in the DOM extension. In PHP 5, a new XSL extension was written and, as ment
ioned, is based on the libxml2 extension. As in PHP 5, the XSL Transformation
does not take the XSLT stylesheet as a parameter but depends on the DOM extens
ion to load it, the stylesheet can be cached in memory and may be applied to m
any documents saving execution time
在 PHP4 中,有两个扩大撑持 XSL 转化。第一个利用 Sablotron 扩大而第二个在 DOM 扩
展中利用 XSLT 撑持。在 PHP5 中,写了一个新的 XSL 扩大,提一下,它是基于 libxml
2 扩大的。因为在 PHP5 中,XSL 转换不是提取 XSLT 款式作为一个参数而是依托 DOM 扩
展去读取它,这个款式会被存储到内存中并使用与很多文档来勤俭履行工夫。

SimpleXML
Probably when looking back in a year or two it will be clear that SimpleXML ha
s revolutionized the way PHP developers work with XML files. SimpleXML could r
eally be called "XML for Dummies". Instead of having to deal with DOM or even
worse SAX, SimpleXML represents your XML file as a native PHP object. You can
read, write or iterate over your XML file with ease accessing elements and att
ributes.
也许,回忆曩昔一两年,咱们会很明晰地晓得,SimpleXML 已变革了 PHP 开辟者处置
XML 文件的体例。SimpleXML 可以被真实的叫做"XML for Dummies"。取代 处置 DOM 乃至
更糟的 SAX,SimpleXML 将 XML 文件作为 PHP 对象来描写。你可以读取、写入或使
用迭代便利的会见元素和属性。

Consider the following XML file:
思索上面的 XML 文件:

<clients>
<client>
<name>John Doe</name>
<account_number>87234838</account_number>
</client>
<client>
<name>Janet Smith</name>
<account_number>72384329</account_number>
</client>
</clients>

The following piece of code prints each client’s name and account number:
上面的这段代码打印每一个顾客的名字和帐号:

$clients = simplexml_load_file('clients.xml');
foreach ($clients->client as $client) {
print "$client->name has account number $client->account_number ";
}

It’s obvious how simple SimpleXML really is.
这个例子分明表现了 SimpleXML 是何等的复杂。

And in case there is something advanced you need to do to your SimpleXML objec
t which isn’t supported in this lightweight extension, you can convert it to
a DOM tree by calling dom_import_simplexml(), manipulate it in DOM and covert
it back to SimpleXML using simplexml_import_dom(). Thanks to both extensions u
sing the same underlying XML library switching between these two has been made
a reality.
万一,你需求一些初级的特征感化于 SimpleXML 对象而它自己这类轻量级扩大其实不撑持。
你可以经由过程挪用 dom_import_simplexml() 将它转化为一个 DOM 树,利用 DOM 操作它然
后利用 simplexml_import_dom() 转回给 SimpleXML。多亏了这两个扩大利用不异的底层
XML 库,在它们之间切换已完成。

SOAP
Official native SOAP support in PHP 4 was lacking. The most commonly used SOAP
implementation was PEAR’s but as it was implemented entirely in PHP it could
not perform as well as a built-in C extension. Other available C extensions n
ever reached stability and wide adoption and, therefore, were not included in
the main PHP 5 distribution.
在 PHP4 中缺少正式的 SOAP 撑持。普通地利用 SOAP 是经由过程 PEAR 失掉撑持。然而,使
用 PHP 作为完成其实不能像利用内置 C 扩大一样精彩。其他可用的 C 扩大不克不及到达不乱性
而普遍的使用。因而 PHP5 的主设置装备摆设没有把它包括出去。(这句仿佛有成绩)

SOAP support in PHP 5 was completely rewritten as a C extension and, although
it was only completed at a very late stage in the beta process, it was incoope
rated into the default distribution due to its thorough implementation of most
of the SOAP standard.
SOAP 撑持在 PHP5 中完整作为一个 C 扩大重写,固然它仅仅在 BETA 版本前期中才完成
。因为它完全的完成 SOAP 的大局部尺度,它已被添加到默许设置装备摆设。

The following calls SomeFunction() defined in a WSDL file:
上面挪用一个 WSDL 文件中界说的 SomeFunction():

$client = new SoapClient("some.wsdl");
$client->SomeFunction($a, $b, $c);

New MySQLi (MySQL Improved) extension [新的 MySQLi (改进的 MySQL) 扩大]
For PHP 5, MySQL AB (http://www.mysql.com/
has written a new MySQL extension
that allows you to take full advantage of the new functionality in MySQL 4.1 a
nd later. As opposed to the old MySQL extension, the new one gives you both a
functional and an object oriented interface so that you can choose what you pr
efer. New features supported by this extension include prepared statements and
variable binding, SSL and compressed connections, transaction control, replic
ation support and more...
为 PHP5,MySQL AB (http://www.mysql.com/
已写了一个新的 MySQL 扩大,该扩大允
许你利用 MySQL 4.1 或更新版本的新函数。与旧的 MySQL 扩大绝对比,新的扩大供应给
你一个函数和一个面向对象接口,因而你可以依据你的喜欢来选择。该扩大撑持新的特征
,包含预声明和可变联合, SSL 和 毗连紧缩, 处置掌握, 复制撑持和其他良多特征。


SQLite extension [SQLite 扩大]
Support for SQLite (http://www.sqlite.org/
was first introduced in the PHP 4.
3.x series. It is an embedded SQL library which does not require an SQL server
and is very suitable for applications which don’t require the scalability of
SQL servers or if you’re deploying at an ISP who doesn’t give you access to
an SQL server. Contrary to what its name implies SQLite is very feature rich
and supports transactions, sub-selects, views and large DB files. It is mentio
ned here as a PHP 5 feature because it was introduced so late in the PHP 4 ser
ies and as it takes advantage of PHP 5 by providing an object oriented interfa
ce and supporting iterators.
SQLite (http://www.sqlite.org/
撑持起首于 PHP 4.3.x 引入。它是一种嵌入式的 SQ
L 库,不包括 SQL 办事器并且十分合适不包括可伸缩性的 SQL 的使用法式、或你正在
利用不撑持会见 SQL 的 ISP。对照它的名字,暗示着 SQLite 是一个具有丰厚特征和事务
撑持、sub-selects、视图和大型的 DB 文件。在这里将它作为 PHP5 的新特征说起,是因
为它在 PHP4 系列很前期才引入的,并且它经由过程供应一个面向对象接口来使用 PHP5 的优
点和撑持迭代。

Tidy extension [Tidy 扩大]
PHP 5 includes support for the useful Tidy (http://tidy.sf.net/
library. It a
llows PHP developers to parse, diagnose, clean and repair HTML documents. The
Tidy extension supports both a functional and an object oriented interface, an
d it’s API uses the PHP 5 exception mechanism.
PHP5 包括一个很有效的 Tidy (http://tidy.sf.net/
库撑持。它答应 PHP 开辟者剖析
、诊断、清算和修复 HTML 文档。Tidy 扩大撑持函数和对象接口,并且它的 API 利用 P
HP5 的异常机制。

Perl extension [Perl 扩大]
Although not bundled in the default PHP 5 package, the Perl extension allows y
ou to call Perl scripts, use Perl objects and use other Perl functionality nat
ively from within PHP. This new extension sits within the PECL (PHP Extension
Community Library) repository a http://pecl.php.net/package/perl.

固然没有综合评价默许的 PHP5 插件,Perl 扩大答应你从 PHP 外部挪用 Perl 剧本、使
用 Perl 对象和利用其他 Perl 功效。该新扩大位于 PECL (PHP 扩大公共库)仓库中。
http://pecl.php.net/package/perl


Other New Things in PHP 5 [其他 PHP5 新事物]:
New memory manager
新的内存办理
The Zend Engine features a new memory manager. The two main advantages are bet
ter support for multi-threaded environments (allocations don’t need to do any
mutual exclusion locks) and after each request freeing the allocated memory b
locks is much more efficient. As this is an underlying infra-structure change
you will not notice it directly as the end-user.
Zend 引擎特写了一个新的内存办理。两个次要的长处是更好的撑持多线程情况(分派不需
要再做任何互斥锁定),且在每一个恳求以后将更无效释放分派的内存单位。因为这是一个
基本的底层机关改动,作为终究用户你不会很直接注重到这个变更。

Dropped support for Windows 95
保持对 Windows 95 的撑持
Running PHP on the Windows 95 platform is not supported anymore due to it not
supporting functionality which PHP uses. As Microsoft has officially stopped s
upporting it over a year ago the PHP development community decided that this i
s a wise decision.
在 Windows 95 平台下运转 PHP 将不再被撑持。由于它不撑持 PHP 的功效。因为微软已
经在一年前正式中断对 Windows 95 的撑持,PHP 开辟团队以为这是一个贤明的决议计划。


Summary [总结]
You must surely be impressed by the amount of improvements in PHP 5. As mentio
ned earlier, this chapter doesn’t cover all of the improvements but only the
main ones. Other improvements include additional features, a lot of bug fixes
and very much improved infrastructure. The following chapters will cover PHP 5
and will give you in-depth coverage of the mentioned new features and others
which were omitted.
你一定为 PHP5 的大批改善而打动。因为早期的叙说,该章节没有掩盖一切的而仅仅是主
要的改善。其他还包含帮助特征的改善,一系列毛病的修改和大局部的底层布局的改善。
接上去其它章节将掩盖 PHP5 和给你一个新特征和其他漏掉的详细论述。
  会有很多高手的鼓励,新手的支持,慢慢你劲头就十足,有更多的信心和兴趣去学。
不帅 该用户已被删除
沙发
发表于 2015-2-4 13:14:17 | 只看该作者
本文当是我的笔记啦,遇到的问题随时填充
深爱那片海 该用户已被删除
板凳
发表于 2015-2-9 23:14:59 | 只看该作者
爱上php,他也会爱上你。
简单生活 该用户已被删除
地板
发表于 2015-2-16 01:55:19 | 只看该作者
,熟悉html,能用div+css,还有javascript,优先考虑linux。我在开始学习的时候,就想把这些知识一起学习,我天真的认为同时学习能够互相呼应,因为知识是相通的。
柔情似水 该用户已被删除
5#
发表于 2015-3-4 22:06:42 | 只看该作者
不禁又想起那些说php是草根语言的人,为什么认得差距这么大呢。
飘灵儿 该用户已被删除
6#
发表于 2015-3-11 21:14:01 | 只看该作者
建数据库表的时候,int型要输入长度的,其实是个摆设的输入几位都没影响的,只要大于4就行,囧。
爱飞 该用户已被删除
7#
发表于 2015-3-19 13:29:47 | 只看该作者
使用zendstdio 写代码的的时候,把tab 的缩进设置成4个空格是很有必要的
愤怒的大鸟 该用户已被删除
8#
发表于 2015-3-27 22:10:57 | 只看该作者
我还是强烈建议自己搭建php环境。因为在搭建的过程中你会遇到一些问题,通过搜索或是看php手册解决问题后,你会更加深刻的理解它们的工作原理,了解到php配置文件中的一些选项设置。
第二个灵魂 该用户已被删除
9#
发表于 2015-3-29 11:22:37 | 只看该作者
个人呢觉得,配wamp 最容易漏的一步就是忘了把$PHP$目录下的libmysql.dll拷贝到windows系统目录的system32目录下,还有重启apache。
admin 该用户已被删除
10#
发表于 2015-4-2 11:09:23 | 只看该作者
有位前辈曾经跟我说过,phper 至少要掌握200个函数 编起程序来才能顺畅点,那些不熟悉的函数记不住也要一拿手册就能找到。所以建议新手们没事就看看php的手册(至少array函数和string函数是要记牢的)。
小女巫 该用户已被删除
11#
发表于 2015-4-6 14:07:32 | 只看该作者
我还是强烈建议自己搭建php环境。因为在搭建的过程中你会遇到一些问题,通过搜索或是看php手册解决问题后,你会更加深刻的理解它们的工作原理,了解到php配置文件中的一些选项设置。
冷月葬花魂 该用户已被删除
12#
发表于 2015-4-15 18:58:29 | 只看该作者
基础有没有对学习php没有太大区别,关键是兴趣。
13#
发表于 2015-4-27 10:18:06 | 只看该作者
学习php的目的往往是为了开发动态网站,phper就业的要求也涵盖了很多。我大致总结为:精通php和mysql
变相怪杰 该用户已被删除
14#
 楼主| 发表于 2015-5-1 17:09:24 | 只看该作者
作为一个合格的coder 编码的规范是必须,命名方面我推崇“驼峰法”,另外就是自己写的代码最好要带注释,不然时间长了,就算是自己的代码估计看起来都费事,更不用说别人拉。
老尸 该用户已被删除
15#
发表于 2015-5-11 21:21:50 | 只看该作者
php里的数组为空的时候是不能拿来遍历的;(这个有点低级啊,不过我刚被这个边界问题墨迹了好长一会)
山那边是海 该用户已被删除
16#
发表于 2015-6-4 19:17:03 | 只看该作者
再就是混迹于论坛啦,咱们的phpchina的论坛就很强大,提出的问题一般都是有达人去解答的,以前的帖子也要多看看也能学到不少前辈们的经验。别的不错的论坛例如php100,javaeye也是很不错的。
精灵巫婆 该用户已被删除
17#
发表于 2015-6-11 20:58:56 | 只看该作者
实践是检验自己会不会的真理。
灵魂腐蚀 该用户已被删除
18#
发表于 2015-7-4 01:46:20 | 只看该作者
作为一个合格的coder 编码的规范是必须,命名方面我推崇“驼峰法”,另外就是自己写的代码最好要带注释,不然时间长了,就算是自己的代码估计看起来都费事,更不用说别人拉。
飘飘悠悠 该用户已被删除
19#
发表于 2015-7-7 17:51:15 | 只看该作者
爱上php,他也会爱上你。
谁可相欹 该用户已被删除
20#
发表于 2015-7-11 18:35:01 | 只看该作者
学习php的目的往往是为了开发动态网站,phper就业的要求也涵盖了很多。我大致总结为:精通php和mysql
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-4-28 21:52

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表