This article directory:
PHP5.2 before: AutoLoad, PDO, and mysqli, type constraints
Php5.2:json Support
PHP5.3: Deprecated features, anonymous functions, New magic methods, namespaces, late static bindings, Heredoc and Nowdoc, const, ternary operators, Phar
Php5.4:short Open Tag, array shorthand form, Traits, built-in Web server, detail modified
Php5.5:yield, List () for foreach, detail modification
PHP5.6: constant enhancement, variable function parameters, namespace enhancement
First, PHP5.2 before (2006 ago)
By the way, the features that PHP5.2 has been presented but worth introducing.
AutoLoad
As you may know, the __autoload () function, if defined, is called when an undefined class is used in the code, and you can load the corresponding class implementation file in the function, such as:
function __autoload ($classname) { require_once("{$classname}. php ")}
However, this function is not recommended because only one such __autoload () function can be found in a project because PHP does not allow the name of the function. But when you use some class libraries, there will inevitably be multiple autoload functions, so Spl_autoload_register () instead:
Spl_autoload_register (function($classname) { require_once("{$ ClassName}.php ")});
Spl_autoload_register () registers a function in the list of AutoLoad functions, and when an undefined class is present, SPL [note] invokes the registered AutoLoad function one at a time in reverse order, which means that you can use Spl_ Autoload_register () registers multiple autoload functions.
Note: Spl:standard PHP library, standard PHP libraries, is designed to solve some classic problems (such as data structures).
PDO and Mysqli
That is, PHP data object, PHP, which is the new database access interface of PHP.
In the traditional style, access to the MySQL database should look like this:
//Connect to server, select Database$conn=mysql_connect("localhost", "User", "password");mysql_select_db("Database");//Execute SQL Query$type=$_post[' Type '];$sql= "SELECT * from ' table ' WHERE ' type ' = {$type}";$result=mysql_query($sql);//Print Results while($row=Mysql_fetch_array($result,Mysql_assoc)) { foreach($row as $k=$v) Print"{$k}: {$v}\n ";}//release the result set, close the connectionMysql_free_result($result);Mysql_close($conn);
To be able to make the code implement database-independent, that is, a piece of code for a variety of databases (for example, the above code only for MySQL), PHP officially designed PDO.
In addition to this, PDO offers more features, such as:
1. Object-oriented style interface
2.SQL Pre-compilation (prepare), placeholder syntax
3. Higher execution efficiency, as an official recommendation, with special performance optimizations
4. Support Most SQL database, replace the database without changing the code
The above code will be implemented in PDO:
//connecting to a database$conn=NewPDO ("Mysql:host=localhost;dbname=database", "User", "password");//precompiled SQL, binding parameters$query=$conn->prepare ("SELECT * from ' table ' WHERE ' type ' =: Type");$query->bindparam ("type",$_post[' Type ']);//execute a query and print the resultsforeach($query->execute () as $row){ foreach($row as $k=$v) Print"{$k}: {$v}\n ";}
PDO is an officially recommended, more generic way to access your database, and if you don't have special needs, then you'd better learn and use PDO.
But if you need to use the advanced features that are unique to MySQL, you might want to try Mysqli, because PDO does not include features that are unique to MySQL in order to be able to use it on multiple databases at the same time.
MYSQLI is an enhanced interface for MySQL, providing both process-oriented and object-oriented interfaces, as well as the currently recommended MySQL driver, and the old C-style MySQL interface will be turned off by default in the future.
There are not many new concepts in the usage of mysqli compared to the above two pieces of code, which are no longer presented here, and can be found in the PHP official website documentation [note].
Note: http://www.php.net/manual/en/mysqli.quickstart.php
Type constraints
Type constraints allow you to limit the type of a parameter, but this mechanism is imperfect, and currently applies only to classes and callable (executable types), and to Array (arrays), not to string and int.
// limit the first parameter to MyClass, the second argument to an executable type, and the third argument to an array function $a $b Array $c ){ // ...}
Original address: http://www.jb51.net/article/48150.htm
Summary of new features and features for each version of PHP5