Home Backend Development PHP Tutorial Php5.0 Instructions------PHP5_PHP tutorial born for object-oriented

Php5.0 Instructions------PHP5_PHP tutorial born for object-oriented

Jul 13, 2016 pm 05:24 PM
php5 for object illustrate For

Php5.0 description------PHP5 born for object-oriented PHP5 born for object-oriented -------------------------- ------------------- [Abstract] The object-oriented functions of PHP5 currently under development have been greatly enhanced. What kind of language will the next generation of PHP be? Let’s explain in detail the currently released beta release of PHP5. (1) The birth of Zend 2.0 The basic grammar used by PHP4 today is a script compilation engine called the Zend engine. This is one of the reasons for the excellent functions of PHP4, which is a language generated as an improvement to PHP3. Everyone has always believed that the performance of PHP4 has been greatly improved compared to PHP3 based on the original goals, and it occupies a large share in the world of network programming. The Zend company that developed the Zend engine was merged from the companies founded by Zeev Suraski and Andi Gutmans, the main developers of PHP3, while developing PHP4. Zend's name is a combination of Zeev and Andi's names. Zend's business model is to continuously provide the PHP core of the zend engine to open source, while at the same time increasing the benefits of peripheral product development and sales. Businesses based on open source software are considered to be relatively good typical examples among most struggling companies around the world. ■Limitations of PHP4 Thanks to the success of PHP4, the scope of application of this application is gradually becoming wider. There is talk of using PHP for enterprise-level purposes. Therefore, there is a problem that when building a large-scale website, the reusability of the code is very poor. Specifically, the object-oriented performance of PHP4 is very weak, so technical personnel who are accustomed to using Java and other technologies have many complaints about this. By gradually improving the object-oriented performance of PHP4 and significantly changing the basic grammar, the developers achieved the development goal of updating the PHP description method. ■Zend 2.0 development began. Subsequently, developers at the Zend PHP Center announced the idea of ​​the Zend 2.0 engine as the next generation PHP language engine in July 2001. While targeting [Zend Engine version 2.0: Feature Overview and Design] (http://www.zend.com/engine2/ZendEngine-2.0.pdf), the object-oriented performance has been greatly enhanced. The expansion of the current PHP4 Zend engine is exactly the same as that of PHP3 in the past. This means increasing the major version number of the new language engine, clarifying the method goals, and receiving praise from the development team. The development of Ze2, like the previous Zend engine, runs in the open source mode. The latest source code is fully disclosed on CVS, and because it is for open developers, discussions about development are very active. Now Ze2 has been decided to be used in the next version of PHP, PHP5. The final release time has not yet been determined, but if according to the Newsletter released by Zend Company on April 1, 2003, it should be a Beta Release now. (2) New features of PHP5 Next, please take a look at the enhanced performance of PHP5 in order. The first is the most important object-oriented performance. The entity characteristics of classes are being significantly modified. What I'm talking about here is only about the new features of classes. · The reference transition of objects is the default (default) · Introducing restrictions on accessing properties · Introducing restrictions on accessing methods · Abstract classes and abstract methods · Interfaces · Final declaration · Namespace · Intra-class constants · Class variables · Unified builder · Analysis Constructor (Distructor) · Other ancillary features The above content is based on the version information registered on CVS on April 22, 2003. There is also the possibility of changes before the official release. ■Default reference transition of objects In PHP4, when variable $var1 is used as an entity object of class, if $var2 = $var1; then, in $var2, the copy of $var1 is substituted. Obviously, in order for $var2 to point to the same object as $var1, it must be written as $var2 =& $var1, and & must be added as a reference. In PHP5, object substitution will become an automatic reference transition. In other words, $var2=$var1, both point to the same object. If you want to bring in copy like php4, then you will use the method of importing __clone(). $var2 = $var1->__clone(); Here, clone is preceded by two consecutive "_" (this is only a characteristic of the entity of the class) ■Restrictions on accessing attributes are introduced in PHP4 classes, together with attributes and methods Inside, you can freely access anywhere inside and outside the class without restrictions. Therefore, users have no protection against inadvertent changes to attributes. In PHP5, like C++ and Java, three levels of access restrictions, private, protected, and public, are introduced, allowing class designers to limit the use of properties and methods. Here's what the various access restrictions mean. · Public: You can freely make references and changes anywhere inside and outside the class. · Private: You can only make references and changes in the methods of this class. · Protected: You can make references and changes in the methods of this class and another class that inherits this class. Make reference and changes. In addition, access specification can be written in inherited classes. "var" in PHP4 has the same meaning as public as before. Here's an example to see how access restrictions work.PHP code:------------------------------------------------- ---------------------------------- class Hoge1 { ​private $var1 = A; ​protected $var2 = B; ​protected $ var3 = 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, there are three attributes $var1, $var2, $var3. $var1 is declared private, $var2 and $var3 are protected. PHP code here:-------------------------------- -------------------------------------------------- - $hoge=new Hoge1; echo'var1:'.$hoge->var1.” n” ---------------------------- -------------------------------------------------- -- If you try to refer to a private property that is not allowed to be accessed from the outside, the following error will appear: Fatal error: Cannot access private property hoge1::$var1 in /path/to/script.php on line XX For protected $ The same goes for var2. However, because the $hoge method is not private or protected, the following code can operate normally and return the value of the internal private and protected 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 ----------------------------------------------- --------------------------------------------- Secondly, in order to see the status of the protected attribute, we Try creating a class Hoge2 that inherits Hoge1 PHP code:--------------------------------------------- --------------------------------------------- class Hoge2 extends Hoge1 { ​public $ var3 = 3; function d_var1() { return $this->var1; } function d_var2() { return $this->var2; } function d_var3() { return $this->var3; } } ------ -------------------------------------------------- -------------------------- In class Hoge2, only $var3 is declared as public. When the attribute is protected, it can be accessed from subclasses. The restrictions are determined by the attribute declaration of the subclass. In Hoge2, because $var3 is declared public, Hoge2's $var3 can be accessed from anywhere (the entity is Hoge1's $var3). $var1 is private in Hoge1. Therefore, the $var1 of Hoge1 will not be inherited in the Hoge2 subclass. However, a property named $var1 may be made in Hoge2. Therefore, Hoge1::$ must be clearly distinguished. var1 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 has nothing to do with Hoge1::var1 variable, so there will be no display, because var2 has protected access restrictions, so if you refer to $var2 directly without passing method, a fatal error will occur ■The restrictions on introducing access methods are the same as above, and they are also classified as private. , protected, public · Public: can be called from anywhere · Private: can only be called from the method of this class · Protected: can only be called from the method of this class and subclass The meaning here is the same as Java and C++. , please don’t get confused. ■Abstract classes and abstract methods support the same abstract classes and abstract methods as Java. Abstract methods only provide the calling method of the method name, and do not provide the entity. The class must declare the class itself abstractly. If you want to directly create an object of the abstract class, the following fatal error will occur. Fatal error: Cannot instantiate abstract class ClassName The actual example of the error is 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 as Java. The interface is designed and combined to suit the described external call form. The entities of the interface cannot be recorded.In contrast, a class that implements an interface must hold entities corresponding to the methods of the interface. In addition, classes can implement multiple interfaces, so multiple inheritance is possible. PHP code:------------------------------------------------ ----------------

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/532145.htmlTechArticlePhp5.0 Description ------PHP5 born for object-oriented PHP5 born for object-oriented ---------------------------------------------[Abstract]Currently developed In PHP5, its object-oriented functions have been...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is the difference between php5 and php8 What is the difference between php5 and php8 Sep 25, 2023 pm 01:34 PM

The differences between php5 and php8 are in terms of performance, language structure, type system, error handling, asynchronous programming, standard library functions and security. Detailed introduction: 1. Performance improvement. Compared with PHP5, PHP8 has a huge improvement in performance. PHP8 introduces a JIT compiler, which can compile and optimize some high-frequency execution codes, thereby improving the running speed; 2. Improved language structure, PHP8 introduces some new language structures and functions. PHP8 supports named parameters, allowing developers to pass parameter names instead of parameter order, etc.

Convert an array or object to a JSON string using PHP's json_encode() function Convert an array or object to a JSON string using PHP's json_encode() function Nov 03, 2023 pm 03:30 PM

JSON (JavaScriptObjectNotation) is a lightweight data exchange format that has become a common format for data exchange between web applications. PHP's json_encode() function can convert an array or object into a JSON string. This article will introduce how to use PHP's json_encode() function, including syntax, parameters, return values, and specific examples. Syntax The syntax of the json_encode() function is as follows: st

Source code exploration: How are objects called in Python? Source code exploration: How are objects called in Python? May 11, 2023 am 11:46 AM

Wedge We know that objects are created in two main ways, one is through Python/CAPI, and the other is by calling a type object. For instance objects of built-in types, both methods are supported. For example, lists can be created through [] or list(). The former is Python/CAPI and the latter is a calling type object. But for instance objects of custom classes, we can only create them by calling type objects. If an object can be called, then the object is callable, otherwise it is not callable. Determining whether an object is callable depends on whether a method is defined in its corresponding type object. like

What is the Request object in PHP? What is the Request object in PHP? Feb 27, 2024 pm 09:06 PM

The Request object in PHP is an object used to handle HTTP requests sent by the client to the server. Through the Request object, we can obtain the client's request information, such as request method, request header information, request parameters, etc., so as to process and respond to the request. In PHP, you can use global variables such as $_REQUEST, $_GET, $_POST, etc. to obtain requested information, but these variables are not objects, but arrays. In order to process request information more flexibly and conveniently, you can

How to convert MySQL query result array to object? How to convert MySQL query result array to object? Apr 29, 2024 pm 01:09 PM

Here's how to convert a MySQL query result array into an object: Create an empty object array. Loop through the resulting array and create a new object for each row. Use a foreach loop to assign the key-value pairs of each row to the corresponding properties of the new object. Adds a new object to the object array. Close the database connection.

Use Python's __contains__() function to define the containment operation of an object Use Python's __contains__() function to define the containment operation of an object Aug 22, 2023 pm 04:23 PM

Use Python's __contains__() function to define the containment operation of an object. Python is a concise and powerful programming language that provides many powerful features to handle various types of data. One of them is to implement the containment operation of objects by defining the __contains__() function. This article will introduce how to use the __contains__() function to define the containment operation of an object, and give some sample code. The __contains__() function is Pytho

Use Python's __le__() function to define a less than or equal comparison of two objects Use Python's __le__() function to define a less than or equal comparison of two objects Aug 21, 2023 pm 09:29 PM

Title: Using Python's __le__() function to define a less than or equal comparison of two objects In Python, we can define comparison operations between objects by using special methods. One of them is the __le__() function, which is used to define less than or equal comparisons. The __le__() function is a magic method in Python and is a special function used to implement the "less than or equal" operation. When we compare two objects using the less than or equal operator (<=), Python

What is the difference between arrays and objects in PHP? What is the difference between arrays and objects in PHP? Apr 29, 2024 pm 02:39 PM

In PHP, an array is an ordered sequence, and elements are accessed by index; an object is an entity with properties and methods, created through the new keyword. Array access is via index, object access is via properties/methods. Array values ​​are passed and object references are passed.

See all articles