Proof of PHP5.6 New characteristic example

Source: Internet
Author: User
Tags certificate fingerprint constant file upload gmp hash scalar unpack

PHP5.6 has released the alpha version, which indicates what new features PHP5.6 brings to the next big version of the upcoming upgrade? This article describes these features and discusses what benefits they can bring to developers.

Constant scalar expression (Constant scalar expressions)

When constants, property declarations, and function parameter defaults are declared, the previous version allows only constant values, and PHP5.6 begins to allow scalar expressions that contain numbers, string literals, and constants.

The code is as follows Copy Code

<?php
const ONE = 1;
CONST TWO = one * 2;

Class C {
Const THREE = two + 1;
Const ONE_THIRD = One/self::three;
Const SENTENCE = ' The value of '. THREE. ' is 3 ';

Public function f ($a = one + Self::three) {
return $a;
}
}

Echo (New C)->f (). \ n ";
Echo c::sentence;

The above code output:

4
The value of THREE is 3
Variable parameter functions (Variadic functions via ...)

The implementation of a variable parameter function, no longer dependent on the Func_get_args () function, is now available through the new operator ... Implemented in a more concise manner.

The code is as follows Copy Code

<?php
function f ($req, $opt = null, ... $params) {
$params is an array containing the remaining arguments.
printf (' $req:%d; $opt:%d, number of params:%d '. " \ n ",
$req, $opt, Count ($params));
}

f (1);
F (1, 2);
F (1, 2, 3);
F (1, 2, 3, 4);
F (1, 2, 3, 4, 5);
The above code output:

$req: 1; $opt: 0; Number of params:0
$req: 1; $opt: 2; Number of params:0
$req: 1; $opt: 2; Number of Params:1
$req: 1; $opt: 2; Number of Params:2
$req: 1; $opt: 2; Number of Params:3

Parameter unpack function (Argument unpacking via ...)

When you call a function, you pass the ... An operator can unpack an array or an Ergodic object into a parameter list, similar to an splat operator in a language such as Ruby.

The code is as follows Copy Code

<?php
function add ($a, $b, $c) {
Return $a + $b + $c;
}

$operators = [2, 3];
echo Add (1, ... $operators);

The above code output:

6
Import functions and constants (use function and use const)

The use operator begins to support the import of functions and constants. Examples of uses of the use function and using const structures:

The code is as follows Copy Code

<?php
Namespace Name\space {
Const FOO = 42;
function f () {echo __function__. " \ n "; }
}

namespace {
Use const Name\space\foo;
Use function name\space\f;

echo FOO. " \ n ";
f ();
}
The above code output:

42
Name\space\f
phpdbg

PHP has an interactive debugger phpdbg, which is a SAPI module with more information referenced phpdbg documentation.

Php://input can be reused

Php://input began to support multiple open and read, which has greatly improved the memory footprint of the modules that handle post data.

Large File Upload support

Can upload more than 2G of large files.

GMP support operator overload

GMP object support operator overloading and conversion to scalar, improve the readability of the code, such as:

The code is as follows Copy Code

<?php
$a = Gmp_init (42);
$b = Gmp_init (17);

Pre-5.6 Code:
Var_dump (Gmp_add ($a, $b));
Var_dump (Gmp_add ($a, 17));
Var_dump (Gmp_add ($b));

New Code:
Var_dump ($a + $b);
Var_dump ($a + 17);
Var_dump (+ $b);

New Gost-crypto Hash algorithm

The Gost-crypto hash algorithm is implemented using Cryptopro s-box tables, and the details refer to RFC 4357, section 11.2.

SSL/TLS Improvement

OpenSSL expands the new certificate fingerprint extraction and verification feature, Openssl_x509_fingerprint () is used to extract the fingerprint of the X.509 certificate, SSL stream context option: Capture_peer_cert Used to get the other X.509 certificate; Peer_fingerprint is used to assert that the opposing certificate matches the given fingerprint.

In addition, you can specify encryption methods, such as SSLv3 or TLS, through the SSL streaming context option Crypto_method, which currently supports the option values including Stream_crypto_method_sslv2_client, stream_crypto_ Method_sslv3_client, Stream_crypto_method_sslv23_client (default), or Stream_crypto_method_tls_client.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.