Php5.0 description------An object-oriented php5_php tutorial

Source: Internet
Author: User

Php5.0 illustrates that the object-oriented php5 is an object-oriented PHP5---------------------------------------------[abstract] PHP5 in the current development, Its object-oriented function has been greatly enhanced. What kind of language will the next generation of PHP be? Let's take a detailed look at the beta release of the PHP5 currently released. (i) The birth of Zend 2.0 the basic grammar used by the PHP4 now is the script-compiling engine called the Zend engine. This is one of the reasons for PHP4 's excellent function, which is a language generated as a result of the improvement of PHP3. Everyone has always believed that PHP4 performance according to the original goal, than PHP3 has a great increase in the network programming world occupies a large share. The Zend Company, which developed the Zend Engine, was incorporated in the development of PHP4 by a company created by PHP3 's main developer Zeev Suraski and Andi Gutmans. The name of the Zend is made up of the names of Zeev and Andi. Zend's business model is to continuously provide the PHP core (core) of the Zend Engine for open source, while improving the benefits of developing and selling peripheral products. The business of using open source software as a base disk is a good example of the most struggling companies around the world. The limitations of PHP4 PHP4 success, and the scope of application of this use is gradually becoming wider. Using PHP as an enterprise-class use is something to hear. Therefore, there is a problem, when building a large-scale web site, the code is very poor re-use. Specifically, PHP4 's object-oriented performance is weak, so technicians accustomed to using Java have a lot to complain about. Gradually improve the object-oriented performance of PHP4, greatly changing the basic grammar, the developer has reached the goal of updating the PHP description method. Zend 2.0 started development Subsequently, developers of the Zend Company's PHP Center published the idea of the Zend 2.0 engine as the next generation PHP language engine in July 2001. With [Zend Engine version 2.0:feature overview and Design] (http://www.zend.com/engine2/ Zendengine-2.0.pdf) as a target, the object-oriented performance is greatly enhanced. The current expansion of the PHP4 Zend engine is the same as that of the former PHP3. This means that to upgrade the major version number of the new language engine,To meet the praise from the development community. The development of Ze2, like the previous Zend engine, is run in open source mode. The latest source code is fully disclosed on CVS because it is open-minded, and the discussion about development is very active. Now Ze2 is decided to use the next version of PHP PHP5. The time for the final release is now undecided, but it should be beta release, according to the Zend Company's April 1, 2003 release of newsletter. (ii) new features of PHP5 Next, look at the performance of the hardened PHP5 in order. The first is the most important object-oriented performance, and the entity properties of the class are greatly modified. This is only a new feature of the class. The reference transition for an object is the default (defaults) · Restrictions on introducing access attributes · Limitations of introducing access Methods · Abstract classes and Abstract methods · Interface Final Statement · Name Space · In-Class constants · Class variables · Unified Builder · destructor (Distructor) · Other ancillary features the above content is based on the data of the registered version of CVS on April 22, 2003, and there is a possibility of change before the official release. The default reference transition for an object is in PHP4, if $var2 = $var 1 When the variable $var1 is the entity object of the class, and in $var2, the copy of $var 1 is replaced. Obviously, $var 2 to point to the same object as $VAR1, it is necessary to write $var2 =& $var 1, must add & as a reference. In PHP5, the object's generation will become an automatic reference transition. That is, $var 2= $var 1, and they point to the same object. If you want to bring copy to the same PHP4, you will apply the method of importing __clone (). $var 2 = $var 1->__clone (); Here, clone is preceded by two contiguous "_" (which is just the attribute of the entity of the Class) in the PHP4 class, along with the properties and methods, which can freely access the inside and outside of the class without restriction. As a result, users cannot prevent inadvertent changes to properties. And in PHP5, like C + + and Java, the import of private, protected, public three levels of access restrictions, so that class designers can use the properties and methods to limit the method. The following are the meanings of the various access restrictions. Public: Be free to refer to, change, or modify any place within or outside the class Private: Can only be referenced, changed in the method of this class · ProtecTed: The ability to reference and change in this class and in the methods of another class that inherits the class. In addition, in the inherited class, you can write access to the specified. The "Var" in PHP4, as in the past, has the same meaning as public. Here's an example, let's see how access restrictions work. PHP Code:--------------------------------------------------------------------------------class Hoge1 {private $var 1 =  A  Protected $var 2 = B;  Protected $var 3 = C;   function Setlower () {$this->var1 = A;   $this->var2 = b;  $this->var3 = c;  } function Var1 () {return $this->var1;  } function Var2 () {return $this->var2;  } function Var3 () {return $this->var3; }}--------------------------------------------------------------------------------in this class, with $var1, $var 2, $ VAR3 three properties. $var 1 are declared private, $var 2 and $var3 are protected. PHP code here:-------------------------------------------------------------- ------------------$hoge =new Hoge1; Echo ' var1: '. $hoge->var1. ' N '-------------------------------------------------------------------------------- If you attempt to reference a private property that is not allowed to be accessed externally, the following error occurs: Fatal error:cannot access private hoge1:: $var 1 IN/PATH/TO/SCript.php on line XX is the same for protected $var2. However, because the $hoge method is not private and protected, the following code works correctly, returning the values of the internal private and protection variables. PHP Code:--------------------------------------------------------------------------------echo var1:. $hoge->var1 (). " "; Var1:a echo var2:. $hoge->var2 (). " "; Var2:b echo VAR3:. $hoge->var3 (). " "; Var3:c $hoge->setlower (); echo var1:. $hoge->var1 (). " "; Var1:a echo var2:. $hoge->var2 (). " "; Var2:b echo VAR3:. $hoge->var3 (). " "; Var3:c--------------------------------------------------------------------------------Second, To be able to see the state of protected's properties, we tried to create a class Hoge2 PHP code that inherits the Hoge1:------------------------------------------------------------  --------------------class Hoge2 extends Hoge1 {public $var 3 = 3;  function D_var1 () {return $this->var1;  } function D_var2 () {return $this->var2;  } function D_var3 () {return $this->var3; }}--------------------------------------------------------------------------------inIn class Hoge2, only $VAR3 is declared as public. In the case where the property is protected, the restriction of access from the subclass is determined by the property declaration of the child class. In Hoge2, because $VAR3 is declared public, Hoge2 's $var3 can be accessed from anywhere (the entity is Hoge1 $VAR3). Because $var1 is private in Hoge1, $var1 in the Hoge2 subclass is not inherited, and in Hoge2 it is possible to make a property named $var1, so it is important to differentiate Hoge1:: $var 1 and hoge2::$ Var1. PHP code:--------------------------------------------------------------------------------$hoge = new Hoge2; echo var1:. $hoge->var1.   " "; VAR1://Echo VAR2:. $hoge->var2.  " "; Error echo VAR3:. $hoge->var3.   " "; Var3:3 echo var1:. $hoge->d_var1 (). " "; Var1:echo var2:. $hoge->d_var2 (). " "; Var2:b echo VAR3:. $hoge->d_var3 (). " "; Var3:3--------------------------------------------------------------------------------$hoge->var1 is with Hoge1: : Var1 does not have any related variables, so there will be no display, because VAR2 has protected access restrictions, so a fatal error can occur if you refer directly to $var2 without using method. The restrictions on the introduction of access methods are the same as above, there are three kinds of private, protected and public. Public: can be called from anywhere · Private: can only be called from within the method of this class · Protected: The only thing that can be called from this class and subclass method is the same as Java and C + +, please don't confuse it. Abstract (ABStract) classes and abstract methods support the same abstract classes and abstract methods as java. Abstract methods provide only a way to invoke the method name, not an entity. In addition, classes that hold abstract methods must abstract the declaration class itself. If you want to make an object directly into an abstract class, the following fatal error will occur. The actual examples of Fatal Error:cannot instantiate abstract class ClassName produce errors are as follows: PHP code:---------------------------------------  -----------------------------------------Abstract class Myabstract {abstract public Function test ();  Public Function test2 () {echo "Myabstract::test2 () called.";  }} class Myimplement extends Myabstract {public Function test () {echo "myimplement::test () called."; }} $obj = new myimplement; $obj->test ();?>--------------------------------------------------------------------------------Interface ( Interface) supports the same interface (interface) as Java. Interfaces are designed to be combined with the described external invocation form. The entity of the interface cannot be logged. Instead, the class that implements the interface must hold the entity corresponding to the method of the interface. In addition, a class can implement multiple interfaces, so it is possible to implement multiple inheritance. PHP Code:-------------------------------------------------------------

http://www.bkjia.com/PHPjc/532145.html www.bkjia.com true http://www.bkjia.com/PHPjc/532145.html techarticle Php5.0 illustrates that the object-oriented php5 is an object-oriented PHP5---------------------------------------------[abstract] PHP5 in the current development, Its object-oriented function has ...

  • Related Article

    Contact Us

    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.

    Tags Index: