What's new What's new PHP 7.1.0
From the 1st day of December, this year's most recent version of PHP, PHP 7.1.0 is available. Following a major update which improved PHP up from 5.6 straight to 7.0 that significantly increased speed, PHP is now focusing on the features of PHP which will assist all of users write more efficient codes. In this article I'll examine the most significant improvements and new features included in PHP 7.1.0. Additionally, it is possible to review the official changelog.
- Nullable Types
- Iterable Returns and Void Returns
- Multi-Catch Exception Handling
- Keys Can Now Be Utilized in Lists
- More Negative String Offsets
- Operators of Numbers and unformed Numbers
- PHP 7.1 and 7.2 for the users
Nullable Types
One of the most discussed additions will include the nullable types which have been missing. Variables can already give the value of a single type or perhaps the value of null. Also, you can make a programming parameter not return null as default. PHP 7.1 supports null as a return kind for operations.
We will look into the consequences of this. There are several return types which you may recognize from old 7.0.
Function findNumber() is a function that returns an int value of 6. // Returns an int and everything is good. Call the function callNumber() will return'six' int return an int, and is able to cause an error to occur if it's called.
A question mark added before the declaration of the class allows null as a return value.
function call, getNumber() int = null return null is acceptable it's okay, everything's good
The syntax is very similar to that of typehinting parameters. The following example illustrates this.
Function showColor(?string color) will echo $color showColor( #ff9900' );It works perfectly with a given string. shown color( Null );// is perfect, the null parameter can be utilized
I am awestruck by this function because the more precise the code you write, the better it is for us to work together. Type declarations can also be helpful in identifying any issues ahead of time and is beneficial for all.
There is no void and iterable returns
As we're discussing the topic of return types There are two kinds that are completely fresh that are not void. and iterable. Void is an excellent choice to perform operations that don't need return values.
function perform_a_job() : void return; // This is fine, it returns null function perform_a_task() : void // This is also fine, it returns null function perform_another_task() : void return true; // This will return an error since it is not void
This is another way to ensure that our code is self-documenting. The issue of whether or not functions that do not return any results can be utilized is up to debate. However we can employ an established mechanism for indicating the behavior.
Iterable can be a term for a numerical number that can be used to traverse as an array. The benefit of iterable is that it can be used it to determine an object which implements the interface of an iterator.
function fonc01(iterable $data) foreach ($data as $key => $val) //.... fonc01(new SplFixedArray(5)); // Works kist fine, SplFixedArray implements Iterator // See http://php.net/manual/en/class.splfixedarray.php
(Thanks Pascal Martin for the example). Pascal Martin for the example)
Are you interested in knowing the ways we have increased the number of visitors we have by 1000 percent?
Join over 20,000 people for our email newsletter with insider WordPress tricks!
Multi-Catch Exception Handling
For a long time it was the case that an attempt block could contain several exceptions, we had to separate them regardless of whether they employed the similar method of handling. This was solved with PHP 7.1 with the ability to allow the catching of multiple exceptions at once.
try // catch some type of code (FirstException SecondException $e) The First and Second exceptions are dealt with
Keys can be utilized to create lists
When the term list()
looks like an operation, it's actually an expression of the language. It's very as array()
. This is utilized to make the list of variables at the same way.
Up to now, it was only possible to use numeric arrays that start with the zero. From 7.1.0 beginning with 7.1.0 to 7.1.0, you're allowed to utilize keys using list()
, or it's possible to utilize the shorthand: []
. Look over the following examples of php.net.
$data =["id" = 1 "name" => 'Tom '],["id" is 2 "name" = "Fred '][/ List() stylelist() stylelist("id" ="id" = "name" =>"name1) = $data[0] [style["id" ="id1" = "name" is the equivalent of $name1"id" = $data[0] // List() stylesforeach ($data as list("id" ="name" = "name" =>"name")) // / logic here using the $name and $id"styleforeach" ($data includes ["id" =>"id" = "name" and name"id" = $id "name") and $name) The logic here is that $id is the id.
A Negative Offset for Strings
PHP 7.1.0 provides a greater selection of options for negative offsets for strings. It is possible to use negative offsets is made possible by employing the []
in conjunction with strings. Take a look at the astonishing results:
$name is "Daniel";echo "My name is the form of "$name[-1 ]".. Nice! ";
Core functions such as strpos are being updated to help make our codes simpler and understandable.
Number Operators, Malformed Numbers and Numbers
It is possible to add 5+ "3"
in PHP and will be evaluated to 8 . It's a blessing to some, and a curse for others. The problem becomes more complex when you consider that five plus "three"
evaluates to five.
It's extremely inefficient and could result in all sorts of trouble later. PHP 7.1.0 seeks to correct the issue by notifying you there's something amiss with the program, such as the image below. This will continue to function in the same way as PHP converts the input string to a three. A second option will issue an alert or a notice.
Other PHP 7.1.0 Small Added Features
In addition to the numerous bugs that require minor fixes In addition, there are some minor features which should at least be noted
- SHA3 fixed mode algorithms added
- This function was added to the iterable() function.
- Implement Closure::fromCallable
- Help with HTTP/2 Server Push
- The MCrypt library has been removed and is scheduled to be eliminated in the next version.
Additional Reading
Be sure to look over these testing of performance for PHP 7.1.0 against PHP 7, and PHP 5. To download the source code of PHP 7.1.0 go to the PHP downloads page.
PHP 7.1, 7.2, and 7.3 to users
Reduce time, money and improve site performance by:
- Support 24/7 and 24 hours a day, 7 days a week From WordPress specialists in web hosting, on call all hours of the day.
- Cloudflare Enterprise integration.
- Global audience reach with 35 data centers across the globe.
- Optimization through the integrated Application Performance Monitoring.
This post was posted on here