Frequently asked questions about PHP 7.3 [FAQ]

Coding (Php 7.x)

Dec 2, 2018

Check out all the new features of PHP 7.3 in small pieces that are easy to digest
 
/img/blog/frequently-asked-questions-php-7-3.jpg

For each release of a new version of PHP there is new information that you as a web developer must assimilate.


With the release of PHP 7.3 this rule does not change,
between deprecations, syntax improvements and various changes you must always be updated.

 

As a reference of this FAQs page you will find several blog posts that describe all the features in detail,

 

Follow the series ...

This blog post is the third part of  "PHP 7.3 and its Christmas gifts"

If you did not read the other parts yet

You can check the other blog posts following the links below 
Introduction to PHP 7.3 and new Syntax
New features of PHP 7.3
Deprecation and Changes

 


Meanwhile, below you will find a list of answers to the most frequent questions asked about this topic.

 

What are the new updates on PHP 7.3?

+
The updates of PHP 7.3 can be divided into four sections, they include Syntax, Deprecation, New features, and miscellaneous Changes.

What are the changes in heredoc in PHP 7.3?

+
in PHP 7.3 the syntax of the heredoc command and nowdoc becomes less rigid, the last token does not need to be the first string of the new line anymore, also you can add other expressions as characters permitted after the ending token.

Can I write a comma at the end of arrays?

+
A trailing comma has been a problem for web developers, forgot to put them somewhere needed or adding them where PHP does not allow can turn quickly in a complete nightmare. Now instead, as long as you use only one comma, you can add it at the end of the list and the script will parse smoothly.

What is new about the list function?

+
PHP 7.3 allows you to assign variables by references within the parameters of the list function, the advantage of it is that now we could edit a single variable rather than find the index within the array..

Can I handle JSON errors in PHP?

+
Not having an adequate way to handle errors when using JSON has been a problem for quite a long time, in PHP 7.3 the json_encode function has now an optional parameter that is: JSON_THROW_ON_ERROR ,this will catch the error and display it using the getMessage() and getCode() methods of the exception EncryptException.

How to check if something is countable?

+
PHP 7.2 added a warning that shows up whenever the web developer was counting or trying to loop an uncountable element. The team that developed added a new function that will help the web developer immensely. The is_countable function takes a variable as a parameter and then return a boolean depending if the function is countable or not.

How can I get the first key of an array in PHP?

+
Despite the vast numbers of tools available, at the moment, if we need to retrieve the first or the last key of an array we have to get all the keys using array_keys() and only then go for the first or last values of the array. Another way is to opt for end() or reset(). array_key_first() instead, helps the web developer providing the name of the first key of the array indicated as a parameter.

How can I get the last key of an array in PHP?

+
Despite the vast numbers of tools available, at the moment, if we need to retrieve the first or the last key of an array we have to get all the keys using array_keys() and only then go for the first or last values of the array. Another way is to opt for end() or reset(). array_key_last() instead, provide the last key of an array indicated as a parameter.

Are array_value_first and array_value_last valid function in PHP?

+
No, they have been proposed on the RFC of PHP 7.3 but they were not been accepted, thus are not available .

Why the proposal of include array_value_first() and array_value_last() into PHP has been refused?

+
In certain cases, like an empty array, the value returned would have been ambiguous, which can overcomplicate the code and add more problem to the web developer.

What are Same-site cooking?

+
Same-site cooking declares that cookies must be sent only with request initiated from the same domain. This is not an official standard but Google Chrome and several of the best PHP frameworks already implement it whereas Firefox and new version of other frameworks confirmed that they are planning to do so. .

How Same-site cooking works in PHP 7.3?

+
Two values can be added to the same site flag present in the above functions. They are Lax and Strict. Cookies that are using Lax will be accessible in a GET request that comes from another domain, while on the contrary Strict will not be accessible in a Get request..

Are Same-site cooking fully supported by the browsers ?

+
No, some browsers are starting to implement it but, the main risk implied for using the same-site flag as a supplementary argument is that it might never become an official standard. It means that eventually browser will downturn the flag. If this happens and you have already implemented it, it will result in you applications stuffed with junk code that need to be removed..

What is wbmp?

+
Wbmp format also known as Wireless Bitmap is monochromatic image optimized for mobile devices.

What is image2wbmp() in PHP?

+
This function accepts 3 parameters (the resource, a string with the path to the saved file and foreground colour in integer format) and returns a boolean value depending on the outputs of the saving of the wbmp version of the image provided.

Why image2wbmp() has been deprecated?

+
The reason why this function has been deprecated and it will be definitely deleted in the future version of PHP is that there is already a function that has exactly the same functionality.

What are FILTER_FLAG_SCHEME_REQUIRED and FILTER_FLAG_HOST_REQUIRED ?

+
These two are flags that belong to the filter_var() function. filter_var() filters variables with the flags specified by the web developers. These are values of a flag that needs to be used as a parameter and contains the ID of the filter that needs to be applied.

Why FILTER_FLAG_SCHEME_REQUIRED and FILTER_FLAG_HOST_REQUIRED are now deprecated?

+
Since PHP 5.2.1 these two flags are included in FILTER_VALIDATE_URL even though you do not specify them. So, these two constants are useless and as written in the RFC they have created the wrong impression that either the scheme and the host can be disabled.

Are there any changes in case-insensitive constants?

+
The possibility to define the third parameter of a define function in PHP as TRUE has been deprecated and will be definitely removed in version 8.0.0; It won't be possible to access a case-insensitive constant with a format that is different from the one used in the define function anymore.

How do I fix my code since PHP 7.3 deprecated case-insensitive constants?

+
To fix all the possible issue with the code you need to do a few resources. You must be looking for all the constants declared case-insensitive. The good news is that you have to declare the constants that way outright just check for define function with the third parameter set as true.

What is PCRE?

+
Perl Compatible Regular Expressions, also called PCRE is a library that PHP uses for dealing with Regular Expressions. PCRE is composite as a set of function that implements regex pattern matching the same syntax and semantics of Perl 5.

How PCRE's update affect my web applications?

+
PCRE is a core functionality of PHP, thus for the most, it won’t affect the user of the language but you need to be aware of some modification that may affect how you work with PHP currently.

What are the differences between PCRE and PCRE2?

+
PSRE2 is more strict in the pattern validations, so, some of your existing patterns could not compile anymore. Also, PHP does not lint regex during the linting time, It is advised to check all the regex you are using in your applications and test them with PHP 7.3. Exakat.io provides a complete list of the regex inventory.

What are the issues you can face when update PCRE2?

+
Implementing PHP 7.3 may be a little bit more problematic than the other seen previously, in fact, some calls to preg_match() could stop working. Before upgrading your PHP to the 7.3 version I advise to check it and, in case, update or rewrite the pattern you need..

What does the compact() function do in PHP??

+
compact() is an amazing array function that allows the creation of array by using the name of one or more variables as parameters.

How does the compact() function change in PHP 7.3?

+
A characteristic that this method did provide is that if we insert a string that refers to a variable that does not exist, the script will simply ignore the parameter. Now, compact() will start to report these missing variable with the following notice.

What is Argon2?

+
PHP 7.2 implemented a new hashing algorithm called Argon2 that is meant to be an alternative to Bcrypt. Argon2 comes in three different versions: Argon2d, Argon2i and Argon2id.

What change there are in Argon2?

+
You have the possibility to add the constant PASSWORD_ARGON2ID as a flag of the password_hash() function. There are several details about this new method like parallelism factor, memory cost and time cost calculations.

 

 

 

This is just a series of questions and answers on the updates that the new version of PHP will bring to your computer,


For more details on each of the features described above take a look at the blog posts below.

 

PHP 7.3 and its Christmas gifts

 

This FAQs page is a part of  "PHP 7.3 and its Christmas gifts"

If you did not read the other parts yet

You can check the other blog posts following the links below 
Introduction to PHP 7.3 and new Syntax
New features of PHP 7.3
Deprecation and Changes

 

 

 
 
If you like this content and you are hungry for some more join the Facebook's community in which we share info and news just like this one!

Other posts that might interest you

Coding (Php 7.x) Nov 25, 2018

Deprecations and Changes for PHP 7.3 [Avoid Errors]

learn more See details
Coding (Php 7.x) Dec 9, 2018

PHP basics for expert web developers (1' part)

See details
Get my free books' review to improve your skill now!
I don't want to improve