Source: PHPBuilder.com
Original Author: Luis Argerich
Translation: erquan
Erquan note: I have not had time to experience PHP5 yet. I just translated an article about foreigners.
The following are all translated by erquan. 1st times of doing these things do not mislead everyone. Sorry for any inaccuracy.
You can't do this. If you do, you may have translated it. If you don't, you may have translated it. Otherwise, you may be too tired to mislead everyone .... :)
Please indicate the source of the article when posting the post. Thank you :)
The official version of PHP5 has not yet been released, but we can learn and experience the new PHP features that the development version has brought to us.
This article will focus on the following three new features of PHP5:
* New Object Mode
* Structured Exception handling
* Namespace
Note the following before the official start:
* Some examples in this article are implemented using the PHP4 method to enhance the readability of the article.
* The new features described in this article may differ from those described in the official version. Please refer to the official version.
* New Object Mode
The new object mode of PHP5 is greatly upgraded based on PHP4. You will look like JAVA :(.
The text below will give a brief introduction to it, with a small example to let you start to experience the new features of PHP5
Come on ~~ :)
* Constructor and Destructor
* Object reference
* Clone object
* Three object modes: private, public, and protected
* Interface
* Virtual class
* _ Call ()
* _ Set () and _ get ()
* Static members
Constructor and Destructor
In PHP4, a function with the same name as the class name is the constructor of the class by default, and there is no destructor concept in PHP4. (Erquan note: This is the same as JAVA)
But since PHP5, constructor is named _ construct in a unified way, and the destructor __destruct (Erquan note: This is the same as Delphi, it can be seen that PHP5 has absorbed many mature OO ideas ~~) :
Example 1: constructor and Destructor
<? Php
Class foo {
Var $ x;
Function _ construct ($ x ){
$ This-> x = $ x;
}
Function display (){
Print ($ this-> x );
}
Function _ destruct (){
Print ("bye ");
}
}
$ O1 = new foo (4 );
$ O1-> display ();
?>
After running, you will see the output "bye", because the class calls the _ destruct () destructor at the end ~~
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.