The differences between php5.2 and 5.3 are: 1. php5.3 has abandoned functions such as Register Globals and Magic Quotes; 2. Added new magic methods __invoke() and __callStatic(); 3. Support Define constants with const.
The operating environment of this article: windows10 system, php 5.2&&php 5.3, thinkpad t480 computer.
Many friends may not know the difference between php 5.2 and php 5.3. Let’s take a closer look at the differences between these two versions. Let’s take a look at the specific differences.
Let’s take a look at the php 5.2 version first.
php5.2(2006-2011)
JSON的支持 增加了json_encode(),json_decode()等函数
Then let’s take a look at the php 5.3 version.
php5.3(2009-2012)
PHP5.3 is a very big update, adding a lot of new features, and also made some modifications that are not backward compatible. Get up and take a look.
1. Deprecated features
The following features are deprecated. If enabled in the configuration file, PHP will issue a warning at runtime.
Register Globals Magic Quotes Safe Mode
2. Anonymous function
f u n c = f u n c t i o n ( func=function(func=function(arg){ echo $arg; } $func(‘hello’);
3. New magic methods __invoke(), __callStatic();
随着匿名函数的加入,PHP 引入了一个新的魔术方法 __invoke(). 该魔术方法会在将一个对象作为函数调用时被调用: class A { public function __invoke($str) { print "A::__invoke(): {$str}"; } } $a = new A; $a("Hello World"); 输出毫无疑问是: A::__invoke(): Hello World __callStatic() 则会在调用一个不存在的静态方法时被调用。
4. Namespace, but not perfect, Only supports classes
5. Late static binding
6.Heredoc and Nowdoc
Some improvements have been made to Heredoc and Nowdoc, which are used for embedding in PHP code A large string.
7. Use const to define constants
Starting from PHP5.3, it is supported to use const to define constants in the global namespace and classes.
旧式风格: define("XOOO", "Value"); 新式风格: const XXOO = "Value"; const 形式仅适用于常量,不适用于运行时才能求值的表达式: // 正确 const XXOO = 1234; // 错误 const XXOO = 2 * 617; (在5.6版后可以了)
8. Abbreviation of ternary operator
Old style:
echo $a ? $a : “No Value”;
can be abbreviated as:
echo $a ?: “No Value”;
That is, if the ternary operator is omitted The second part will be replaced by the first part by default.
9.Phar
Phar is PHP Archive. It was originally just a library in Pear. It was later rewritten as a C extension in PHP5.3 and built into PHP.
Phar is used to package multiple .php scripts (can also package other files) into a .phar compressed file (usually in ZIP format).
The purpose is to imitate Java's .jar, no, the purpose is to make publishing PHP applications more convenient. It also provides functions such as digital signature verification.
.phar files can be interpreted and executed by the PHP engine just like .php files. At the same time, you can also write code like this to include (require) the code in .phar:
require(“xxoo.phar”); require(“phar://xxoo.phar/xo/ox.php”);
Recommended Learning: php training
The above is the detailed content of What is the difference between php5.2 and 5.3. For more information, please follow other related articles on the PHP Chinese website!