What's new What's new PHP 7.1.0

Nov 18, 2022
php 7.1.0

Since the 1st day in December, the latest version PHP, PHP 7.1.0 is now available. In the wake of a major upgrade that enhanced PHP to go from 5.6 directly to 7.0 that significantly increased speeds, PHP is now focusing on features that are available in PHP which can help all of users write more efficient codes. In this post, I'll discuss the biggest changes and the new features in PHP 7.1.0. Additionally, it is possible to review an official changeslog.

Nullable Types

One of the most debated changes will be the nullable classes which were not present. Variables can already give an individual kind or maybe what is the meaning of null. Additionally, it is possible to create a program parameter to give null in the default. PHP 7.1 includes null as the return type for operations.

We will look into the implications of this. There are a variety of returns that you might be familiar with from 7.0.

Function FindNumber() can be described as a method that returns an int number of six. // returns an int and everything is good. When you call the function callNumber() returns'six int', which is an int, and is able to result in an error if it's called.

A question mark added before that declaration will allow null to be used as a return value.

function call to getNumber() int = null return is acceptable. the way it is, everything's fine.

The syntax is very identical to the syntax of parameters for typehinting. This example illustrates it.

Function showColor(?string color) will echo the $color showColor( #ff9900' );It works perfectly with any string. The color shown( null );// is perfect, the null parameter can be employed

I am awestruck by this feature because the more exact the code you create and the more accurate it is for us to collaborate. Type declarations are helpful in identifying any issues ahead of time and is advantageous for everyone.

php 7.1.0 changes

There's nothing to be void or iterable returns

When we're talking about the subject of return types , there are two varieties which are totally new and don't have any voids. Iterable. Void is an excellent choice to execute operations that don't need returns 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 be sure our program is self-documenting. The question of the possibility that functions which aren't able to produce any results can be utilized is up to discussion. We can however use an established mechanism for indicating the nature of the activity.

Iterable could be the term used to refer to a number that can be utilized to traverse the array. The benefit of iterable is that it can be utilized to identify objects that have the interface for 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 this example)

Are you curious about the methods we've used to increase the amount of visitors we have by 1000 percent?

Join more than 20,000 subscribers to our weekly email newsletter, which includes insider WordPress tips!

Multi-Catch Exception Handling

It was the rule the attempt block could have multiple exceptions. Therefore, we needed to break them apart regardless of whether or not they used the similar method of handling. This was solved with PHP 7.1 which was able to catch several exceptions simultaneously.

attempt to catch any kind or code (FirstException SecondException $e) The first and second exceptions are handled

Keys can be utilized to create lists

If the word"list"() looks like something that's happening, it's really an expression of the language. It's as as array(). This is utilized to make an array of variables similar time.

Up to now, it was only possible to use numeric arrays that start with zero. Starting with 7.1.0 from 7.1.0 to 7.1.0, you're allowed to use keys with list(), or it's possible to utilize the shorterhand [It's possible to use the shorthand: [. Check out the examples below from php.net.

$data =["id" = 1 "name" => 'Tom '],["id" refers to 2 "name" is "Fred '][/ List() stylelist() stylelist("id" ="id" = "name" =>"name1) = $data[0"name1" = $data[0 [style["id" ="id1" means that "name" is the same as $name1"id" = $data[0] // List() styleforeach ($data as list("id" ="name" is "name" =>"name")) /// logic with the $name as $id"styleforeach" ($data comprises ["id" =>"id" = "name" and name"id" = $id "name") (along with the $name) The logic here is that the ID is $id.

A Negative Offset for Strings

PHP 7.1.0 offers a wider variety of choices for negative offsets on strings. You can use negative offsets is made possible by employing this [] together with strings. Look at these astounding outcomes:

Name will be "Daniel";echo "My name is the form of "$name[-1 ]".. Nice! ";

Strpos are a few of the core functions that are updated in order to simplify our code and make it more comprehendible.

Number Operators, Malformed Numbers and numbers

It is possible to add the numbers 5+ "3" in PHP and be evaluated until 8 . It's a good thing for certain however it is a curse for other. It becomes even more complicated as you think about the fact that five plus "three" evaluates to five.

This is incredibly inefficient and may result in all sorts of trouble later. PHP 7.1.0 is a fix for the issue by notifying you there's something amiss in the application like the picture below. This will continue to function exactly the same way, as PHP transforms input strings to a three. Another option is to issue an alert or a notice.

Other PHP 7.1.0 small added features

There are numerous bugs that need minor corrections Additionally, there are some minor features which should at least be noted

  • Fixed mode algorithm SHA3 added
  • This function was added to the iterable() function.
  • Implement Closure::fromCallable
  • Assistance by pushing HTTP/2 Servers
  • The MCrypt library has been removed and will be eliminated with the next version.

Extra Reading

Take a look at the test results for PHP 7.1.0 against PHP 7 as well as PHP 5. For the download of the source code of PHP 7.1.0 visit the PHP Downloads page.

PHP 7.1, 7.2, and 7.3 to the users

 php 7.1
PHP 7.1

Reduce time, money and increase site performance through:

  • Support 24/7 and All hours, seven days per week. WordPress specialists who specialize in hosting websites, you can call all hours of the day.
  • Cloudflare Enterprise integration.
  • Reaching a global audience with 35 data centers around the world.
  • Optimizing through the integration of Application Performance Monitoring.

The post was published on this site.

This post was posted on here