PHP 7.1
. For a complete list of currently approved and discussed changes, check out the official PHP RFC .Curl HTTP/2 server push
supportvoid
list()
function and the new syntax c []
mcrypt()
and its subsequent deletion try { // to do something } catch (MyException $e) { // Handle this exception } catch (AnotherException $e) { // Handle this in the same way as MyException } catch (Exception $e) { // Handle this in a different way }
try { // to do something } catch (MyException | AnotherException $e) { // Handle these exceptions } catch (Exception $e) { // Handle this in a different way }
||
the operator we associate with or
is a single character |
.Curl HTTP/2 server push
supportserver push
? The best way may be to understand this through an example.Server push
aims to speed up boot time and allows you to skip this step, immediately directing resources to the client directly.libcurl
from version 7.44.0
, but is still unstable and has not gone into release (Details: here and here ). For more information, read the official PHP RFC: ext / curl HTTP / 2 Server Push Support .private
or protected
. They are always public
. class Panda { private $pandaId; public $name; // This is public, and there's // nothing you can do about it. const MAGIC_POWER = 20; }
class Panda { // Constants default to public const MAGIC_POWER = 20; private const LIMIT_BREAK = 30; protected const EXPERIENCE_POINTS = 0; public const HEALTH_POINTS = 100; }
void
function foo(): array { return []; }
void
, i.e. it performs the action, but returns nothing. function i_dont_return_anything(): void { // Perform some action // This is perfectly valid. return; // This would throw a Fatal error (A // void function must not return a // value). // return true; }
boolean
, indicating successful execution, but this is a topic for another article. strrpos($needle, $haystack, $offset = 0);
$needle
in $haystack
starting from the beginning of the line, finds the last entry starting from N positions back from the end of $ haystack.$offset
parameter, and some do not. One of the clearest examples is strpos()
. Here, in order to achieve a negative offset, the function must be combined with substr()
, which reduces readability and code performance.$offset
parameter and its behavior with a negative value to many standard functions.list()
function and the new syntax c []
list()
function: $myArray = ['monkey', 'tree', 'banana']; list($monkey, $tree, $banana) = $myArray; // $monkey is now equal to 'monkey'.
_list()
works only with numeric indices of arrays starting from zero, for example, as in the code above. It does not work with associative arrays, such as: $myNamedArray = [ 'name' => 'Amo', 'age' => 32, 'location' => 'London' ];
list('name' => $name, 'age' => $age, 'location' => $location) = $myNamedArray;
[]
to denote an array of variables. This provides an alternative to list()
for dividing an array into variables. [$a, $b, $c] = [1, 2, 3];
$numbers = [1, 2, 3];
//Results in 10 $total = 5 + 5; // Results in 10 $total = '5' + '5'; // Results in 10 $total = 5+ '5'; // Results in 10 $total = '3 bananas yesterday' + '7 bananas today'; // Results in 5 $total = 5 + 'I love bananas';
I love bananas
no numeric values and the whole line is treated as 0. Notice: A non well formed numeric string encountered in file.php on line x
(int) "string"
, but I personally think that if you perform arithmetic operations on such strings, then you should think about the quality of this code.mcrypt()
and its subsequent deletionmcrypt
library was abandoned in 2007 and contains numerous bugs and unmortgaged patches. Thus, the question of its inclusion in PHP has long been ripe for consideration.mcrypt_*
functions will issue an E_DEPRECATED
notification. In PHP 7.1 + 1, they will be completely removed.mcrypt
in your PHP code, you do it wrong .core
changes I didn't mention, please let us know in the comments below. Thanks for reading.Source: https://habr.com/ru/post/302390/
All Articles