📜 ⬆️ ⬇️

PHP 5.3 Review

Days go by, the weather is improving, and meanwhile PHP 5.3 is getting closer and closer - you have to be fully armed.
RC2 came out recently, then RC3, and then Stable (in about a month).

The first thing I want to say: 5.2 is slower than 5.1, but 5.3 is faster than 5.1. 5.3 introduced many optimizations (including linking tables), and this is good news.

There are no particular backward compatibility issues, except for the introduction of new reserved words and other minor points.
These are described in detail here - wiki.php.net/doc/scratchpad/upgrade/53

In addition, there are many innovations:
')
1. mysqlnd.
As you know, PHP communicates with the MySQL server via C-wrapper over libmysql, but the implementation has a huge overhead (for example, when you do mysql_fetch_assoc, the result has as many as three copies in memory).
MySQL Native Driver is an effective replacement for libmysql at the C-level. However, interfaces (mysql, mysqli, PDO) should not suffer from this.

2. Closures.
Are you tired of seeing create_function () under the rim of your toilet bowl?
$lambda = function() {echo 'Hello World!';};
$lambda();


* This source code was highlighted with Source Code Highlighter.

:
class myLambda
{
  public function __invoke() {echo 'Hello World!';}
}
$lambda = new myLambda;
$lambda();


* This source code was highlighted with Source Code Highlighter.
, , :
$var = 'Hello World!';
$func = function() use ($var) {echo $var;};
$func();


* This source code was highlighted with Source Code Highlighter.
preg_replace_callback, .

$this . , .
, , use, .

wiki.php.net/rfc/closures

3. namespaces. .
namespace hello;
class msg
{
 public static function write() {echo 'Hello';}
}
msg::write();
namespace World;
class msg
{
 public static function write() {echo ' World!';}
}
msg::write();


* This source code was highlighted with Source Code Highlighter.
. namespace' , , . .
namespace' — (\).

php.net/namespaces

4. .
true-, .
$var = 'Hello World!';
echo $var?:'false';
// Hello World!


* This source code was highlighted with Source Code Highlighter.
, .

5. Label'. GOTO.
Label' , , Label'.
$i = 1;
start:
echo ($i > 1?'-':'').$i;
if ($i++ < 5) {goto start;}
echo ' ';
// 1-2-3-4-5


* This source code was highlighted with Source Code Highlighter.
.
, :)

6. Garbage Collector.
- PHP , .

7. SPL.

-: http://www.php.net/~helly/php/ext/spl/

, : SplFixedArray, SplStack, SplDoublyLinkedList, SplQueue, SplPriorityQueue. .

, Spl phpinfo() :
$ php -i|less
$ php -r 'var_export(spl_classes());'
$ php --re spl|less

crocodile2u.
Sherman81 .

8. Late Static Binding
__callStatic get_called_class().
.

PCRE 7.9 ( ), sqlite , .

- , , .
!

Source: https://habr.com/ru/post/59876/


All Articles