Great progress of PHP 5

PHP 5.0 officially released on July 13 is one of the events that has attracted attention in the developer community. PHP is currently the most commonly used programming language for building dynamic websites with 16,251,453 domains, and 1,346,521 IP addresses, as of July 18, 2004.

PHP 5.0 officially released on July 13 is one of the events that has attracted attention in the developer community. PHP is currently the most commonly used programming language for building dynamic websites with 16,251,453 domains, and 1,346,521 IP addresses, as of July 18, 2004.

PHP 5.0 has made significant improvements compared to previous 4.x PHP versions. So far, PHP 5 has been considered the most significant update in the last 2 years while maintaining the inherent strength of PHP since PHP / FI 2.0 is speed and efficiency. (Refer to PHP development history on Wikipedia at http://en.wikipedia.org/wiki/PHP and other PHP information on the PHP Vietnam community website at http:/// www. phpvietnam.net).

Back in 1998, putting Zend Engine 1 into the core of PHP Engine gave PHP 4 the superior power. Although PHP has attracted a large number of users, its main limitation is not providing. Add tools to build websites.

Six years later, the community has seriously considered the inherent persistence of PHP that made it difficult for developers to handle some problems. Among them, developers emphasize the support of object-oriented programming in PHP 4 in a half-hearted way, the MySQL extension library does not support the new MySQL 4.1 client protocol, supports mixed and mixed XML. padded.

PHP 5 has improved 3 important issues (completely rewritten) and the results are really impressive. However, this is still not all the best that PHP 5 brings. In this article, I will mention seven outstanding features of PHP 5. These features allow for the development of shorter, more beautiful and more mobile code.

Strong support for object-oriented programming

Although the object support features have been claimed since PHP 4, the developer community has quickly realized their immaturity. With PHP 5, developers now have complete object-oriented programming tools (PHP 5 still allows normal work with structured programming). Can list some characteristics:

1. A completely new object model based on a prototype is Java's model

2. Unified constructor _construct (): facilitates the movement of classes from this class hierarchy to another class hierarchy.

3. Cancellation function _destruct (): facilitates to record information for finding errors, closing data connection and performing other work of releasing resources.

4. Properties and public, protected, and private methods: allow defining the tangibility of class properties. This is very important to support inheritance and encapsulation in object-oriented programming.

5. Interface (Interface): this feature is taken from the Java model to support multiple inheritance.

6. Abstract classes.

7. Class hints (class hints).

8. Static properties and methods.

9. Final properties and methods.

10. A variety of other strong support methods such as auto loading, reflection, exception handling (exceptions), object cloning, instanceof operators .

In addition, the objects are now both assigned and transmitted by reference (reference or handle) instead of by value, so the programmer no longer has to use scattered symbols & throughout the program. . These language features also paved the way for PHP programmers to make the most of the power of pattern designs.

MySQL extension library is completely rewritten

The MySQL database administration system goes hand in hand with PHP as shown with the shadow, although PHP is capable of supporting many other database systems. However, while this combination offers resounding success for both products, the extension of the extension module for PHP to work with MySQL is an obstacle when it does not allow the use of properties. Extremely attractive features of MySQL 4.1 and higher versions.

The PHP 5 development team has written a completely new, very powerful extension library to support MySQL 4.1 and 5.x, called MySQLi (MySQL Improved). Features include:

1. Pre-compilation command

2. Parameter export and import are limited

3. SSL connection

4. Multi-query function.

MySQLi also takes advantage of PHP 5's new object-oriented programming support to provide an object-oriented interface with MySQL. Above all, the latest versions of MySQL now allow subselects, transactions and replication.

XML toolkit can interact

PHP 5 has improved XML support with XML libraries expanded as follows:

1. Work together as a whole.

2. Standardized on a single XML library: libxml2.

3. Fully comply with W3 specifications.

4. Effective data processing.

< 5. Provide powerful XML processing tool.

In addition, in order to continue maintaining the ease of PHP in building web applications, a new XML library has been included to easily read and modify XML documents. The SimpleXML extension module allows interacting with the information contained in an XML document as if the information is an array or an object, can be used to loop through them, edit them in place only by assigning them. New values ​​into variables.

If you already know the format of the document, such as when separating RSS files, configuration data, then use SimpleXML very convenient.

If you like using DOM, you will be very interested in the DOM extension module of PHP 5, this module has been rewritten and greatly improved compared to the version in PHP 4.

Embedded SQLITE database system

Perfect integration with MySQL is a huge advantage for PHP 4.x, but many web applications do not need much to the ability of strong database management system.Therefore, the distribution with the SQLite embedded database system allows developers to have more tools ready to store and query data using the SQL method without installing any separate database system.SQLite correctly handles concurrent access and concurrent access, two outstanding issues when processing self-created flat file files.

SQLite is powerful enough to handle most common data storage and manipulation needs. It supports:

1. Transactions:

2. Subqueries (Subqueries)

3. Referential integrity control (triggers)

4. Many advanced features related to databases such as View support .

SQLite is compatible with most of the standard SQL92 features, but the latest version 3.0 does not yet support nested transitions, foreign key constraints, and support for full referential integrity control.You can even write functions for users to define themselves in PHP and call them inside SQLite.This is the most prominent feature ever obtained in an extended database related module in PHP.

Better error handling mechanism with Exceptions

PHP 5 provides a completely different error checking model than PHP 4. It is called exception error handling.With an exception, the developer is freed from having to check the return value of all functions.Instead, you can separate the error handling programming logic and place them next to the code blocks.

Exception errors are often seen in object-oriented programming languages ​​like Java and C ++.Currently, only a few PHP extension modules use exception errors, but gradually this will be done synchronously.However, you can use the exception error for any of your PHP code.

Advanced SOAP implementation

SOAP is a key component of the rapidly growing web service sector.SOAP support in PHP 4 is only at the middle level, not only with very few SOAP packages but also in the most important packages written in PHP instead of slow C.

With PHP 5, we finally have an extension module for SOAP written in C. Currently, this module is mostly implemented, although not all the features mentioned in SOAP 1.2.In the future, this module will be further improved.Currently, compared to .NET or Java, SOAP support in PHP is still ranked below.

 

INSTALL PHP 5 WITH APACHE 2.0.X AND MYSQL ON WINXP

 

 

The necessary software:
• Microsoft Windows XP or Windows 2000 (I have not tested on Windows 98).
• Apache 2.0.x (I use Apache 2.0.50). You can download the latest Apache 2.0.50 version for Win32 at http://httpd.apache.org/ .
• PHP 5.0 (I will install PHP 5 as an Apache module, in the way that people install PHP for servers). Download the official PHP 5.0 version at http://www.php.net/download or the development version at http://snaps.php.net .
• MySQL 4.0 latest version can be downloaded from http://dev.mysql.com/get/Downloads/MySQL-4.0/mysql-4.0.20d-win.zip/from/pick#mirrors .
INSTALL APACHE 2.0
Apache 2.0.x has an automated installer and you won't have much trouble installing this web server software on Windows. For example, to install Apache 2.0.50, simply download a file named apache_2.0.50-win32-x86-no_ssl.msi and run it. By default it is installed on c: Program FilesApache GroupApache2. However, to facilitate server management and associated modules, I install it on c: webserverApache2. You can refer to the visual guide article at http://www.opensourcevn.org/javavietnam .
After installation is complete, temporarily turn off Apache. However, you may not need to do this until you modify the Apache configuration file below.
INSTALL PHP 5.0
Currently PHP 5 does not have an automatic installer. You download from PHP.net file php-5.0.0-Win32.zip with a capacity of about 7.6 MB. Unzip this file into the directory you choose. For ease of management, I unzip to c: webserverphp5.
After decompressing, you will see PHP 5 has a different directory structure than PHP 4. The reason is that PHP has been rewritten almost entirely for improved performance and speed. However, you do not need to worry, all you need to do after extracting is to find the file php.ini-recommended and perform the following steps:
- Copy it to the Apache folder mentioned above and rename it to php.ini (c: webserverApache2php.ini).
- Use a pure text editor like NotePad or EditPlus to open this file.
- Find the line
extension_dir = '. /'
and replace it with
extension_dir = 'c: webserverphp5ext'
- Find the line
; extension = php_mysql.dll
and remove the ';' at the beginning of the line (applies when you need to use PHP functions that handle data contained in MySQL).
Since the release of PHP 5.0 Beta for the first time, developers have reported that it is set by default not to work with MySQL because the PHP 5.0 installer already contains SQLite, an embedded database administration system. , runs extremely fast, has enough features to use for small businesses. In addition, the main reason is the GPL license issue. However, if you need a more advanced database management system like MySQL, PHP 5 allows you to reconfigure to be ready to work. If you do not pay attention to this, you may encounter the following error:
Fatal error: call to undefined function mysql_connect () prints c: webserverwebroottexttextpatternlibtxplib_db.
phpon line 15
- Also in this php.ini file, you find the line
; session.save_path
and adjust it to
session.save_path = 'c: webserverphp5tmp'
(depending on the directory you installed PHP5).
- Next, go to the [mail function] line, below the line you will see the line
; sendmail_from
Please uncheck the ';' at the beginning of the line and change your email address to your liking.
Example: localhost@phpvietnam.net
This configuration will be used until you program with the mail () function in PHP to send and receive mail with a built-in email server like QK Server.
- Go to the sub subdirectory in the PHP 5 directory (wallet

 

 

For example, c: webserverphp5ext) and check if there is a php_mysql.dll file there. This is the library for PHP 5 to handle data handling calls with MySQL. If you download PHP 5.0 officially, this file is definitely there. But if you use PHP 5.0 versions that are being developed and exported as snapshots (http://snaps.php.net), this file may be removed. If so, find it in the unzipped folder and copy it to the ext subdirectory.
- Copy libmysql.dll file in PHP 5 directory into c: Windowssystem32 folder or bin directory of Apache 2 (for example, c: webserverApache2bin). If you don't do this step, you might get an error 'can't load c: webserverphp5extphp_mysql.dll'.
- Next, go to the Apache conf subdirectory and find the httpd.conf file. If Apache 2.0.x is installed by default, its path is c: Program FilesApache GroupApache2confhttpd.conf. In my case, it is located at c: webserverApache2confhttpd.conf. Open this file with a plain text editor and navigate to the line
#LoadModule ssl_module modules / mod_ssl.so
You add the following two lines below this line:
LoadModule php5_module 'c: /webserver/php5/php5apache2.dll'
AddType application / x-httpd-php .php
The LoadModule line will allow Apache to load the library module called PHP 5 to perform processing tasks related to php files. You need to pay attention to change the path of php5apache2.dll depending on your case.
Now it is time to restart Apache 2. If there are no errors, the system tray appears as shown in Figure 1.

Picture 1 of Great progress of PHP 5

INSTALL MYSQL 4.0
So you have configured PHP 5.0 and Apache 2.0 to run them together. You have also configured PHP 5.0 functions to query MySQL 4.0. However, you need to install MySQL 4.0 to have enough PHP 5 programming tools. Installing MySQL 4.0.20 is quite simple. Just download a .zip file. Unzip and run the setup.exe file. MySQL software will automatically install to the default directory c: mysql. Then go to the folder c: mysqlbin to run the file winmysqladmin.exe. When you run this program, you will see a window as shown in Figure 2.

Picture 2 of Great progress of PHP 5

This window allows you to provide the name / password of the person with full admin rights to the MySQL Server. Usually this name / password pair is root / localhost or you can leave it blank by default. After the import is complete and press the OK button, this window disappears and in the system tray will appear the service icon of MySQL Server as shown in Figure 3.

Picture 3 of Great progress of PHP 5

As such, you already have the MySQL Server running on your computer and ready to handle queries.

CHECK THE INSTALLATION RESULTS
To re-check the installation work, follow these two steps:
• Go to Apache 2htdocs web root directory, and use a pure text editor like Notepad to create a file called phpinfo.php with the content:

Open the browser and type in the address http:///localhost/phpinfo.php. You should see the full configuration of PHP 5. Turn on the Apache Service Monitor program window and you will see something like Figure 4.

Picture 4 of Great progress of PHP 5

Now you can program with PHP 5. Wish you success.

 

 

Pham Cong Dinh

 

PHPVietnam
pcdinh@yahoo.com Reference:
- Changes in PHP 5: http://www.php.net/ChangeLog-5.php
- Wiley PHP5 and MySQL Bible books in 2004.
- PHP and MySQL books for Dummies 2nd Edition 2004 by Wiley Publishing

Repeater (Iterator)

Repeaters are a completely new feature in PHP 5.0. They allow you to use a for-each loop to loop through different data types: directory lists, database result sets, and XML documents. SPL - Standard PHP Library - is a set of repeaters that provides this functionality along with filtering, limiting, caching and changing of repeater results.

Repeaters are a great way to manually remove all the interfering code in your source code.

For example , the DirectoryIterator repeater transforms iterations through directories from writing:

$ dir = opendir ($ path);

while (false! == ($ file = readdir ($ dir))) {

print '$ filen';

}

closedir ($ dir);

into writing:

foreach (new DirectoryIterator ($ path) as $ file) {

print '$ filen';

}

So there is no reference directory pointer lying in a mess, as well as there is no lack of comparison conditions in the need to check inside the loop.

In addition to the above highlights, PHP 5.0 also provides:

• Improving lines (streams), wrappers and filters.

The line is the concept given in PHP 4.3, but before PHP 5.0 it was the least used part. Improvements included in PHP 5.0 Beta 3 allow the file interface to be read and written to data by using protocol-dependent objects, which are often referred to as wrappers. The line also allows changing the flow of data through them by attaching filters.

• Endoscopic code using the Reflection layer.

This set of classes allows you to test classes, methods, parameters, and other things to explore object properties. With them, you can easily create class probes, PHP debuggers and other tools based on collecting object and function details.

Generate standard HTML code thanks to Tidy.

The Tidy extension module makes it easy to understand the validity of HTML and XHTML generation. Its smart parser even turns the most arbitrary code-writing pages into pages that strictly adhere to the latest W3C specifications.

Superior command line processing

The PHP5 command line version now allows processing individual lines, like Perl and awk.You can specify the code to run at the beginning, middle, and end of each line in a file.ÿ

Update 25 May 2019
Category

System

Mac OS X

Hardware

Game

Tech info

Technology

Science

Life

Application

Electric

Program

Mobile