Warning in .librariesclassesdbidbimysqli.php#213 Mysqli_query(): Error Reading Result Set's Header

New features of PHP vii.3 [Consummate guide]

anastasionico HackerNoon profile picture

Introduction

A couple of days ago,

a colleague of mine showed me a Television receiver commercial that was broadcast on Television receiver a few years ago.

the spot in question belonged to a well-known chain of British supermarkets and told of an episode that really happened on Christmas 24-hour interval during the Outset World State of war.

British and German soldiers later on months of disharmonize came out of the trenches and fabricated a truce with lots of laughs and football game matches,

I must admit that those few seconds were enough to cheer up my twenty-four hours and make me retrieve about how people of those times spent the days of this time of year.

During the chat following the video, I realized that in those times despite the obvious reasons that I do not need to mention,

there has been an incredible technological advocacy, only retrieve of the film "The imitation game" by Morten Tyldum.

I believe the same is true for PHP,

improvements, even small-scale ones, to language, syntax, and code in general always bring good humour and hope in the fact that during the months,

even years to come up,

they can make us amend programmers and create applications that make the states and our customers happy.

This year the team in charge of the updates managed to deliver a few but decisive changes,

Some of the new features had been requested for years,

others are pleasant surprises similar those we will receive from our loved ones during the holidays, similar those that, on Christmas day were received past the soldiers.

in this post, you will larn what features volition be implemented in the new PHP 7.3 and which axes in the sleeve you lot can show off from its release.

Follow the serial …

This web log post is the second part of "PHP 7.three and its Christmas gifts

If y'all did not read the other parts yet

You can bank check the other blog posts following the links below
Introduction to PHP 7.3 and new Syntax,
New features of PHP 7.three,
Deprecation and Changes —non published yet, get the ebook if you want to read it now

New Features

JSON_THROW_ON_ERROR

Not having an adequate way to handle errors when using JSON has been a problem for quite a long time, and web developer all over the worlds accept seen this as a huge downside of the language,

The RFC of PHP seven.3 has accepted this update past a 23 vs 0 vote which says how much this feature has been requested.

Until PHP v7.2 we needed to utilize a workaround to go an error from JSON and it was not reliable nor proficient in its job;

Hither is an example:

                json_last_error() === JSON_ERROR_NONE // the result is false              
                json_last_error_msg() // The result is "Syntax error"              

Yes,

we can determinate if JSON had an fault,

only, this is conspicuously not the best method to do so.

The new flag I am about to show you is an excellent alternative because give to the programmer the opportunity to use the power of exceptions that can exist managed within the "try-catch" block of code.

Permit's come across a practical case, shall we?:

utilise JsonException;

try {
$json = json_encode("{", JSON_THROW_ON_ERROR);
render base64_encode($json);
} catch (JsonException $e) {
throw new EncryptException('Could not encrypt the data.', 0, $due east);
}

As you can run across from the previous code the json_encode function has now an optional parameter JSON_THROW_ON_ERROR this will catch the error and brandish information technology using the following exception methods:

                $e->getMessage(); // like json_last_error_msg()              
                $e->getCode(); // like json_last_error()              

The default adaptation of PHP7.three toward your existing lawmaking volition be neutral and since information technology is an optional parameter later you update your PHP everything volition still work as aspected.

This is one of the well-nigh important features of the update so if you want to dig in and acquire more than have a look at the official RFC for JSON_THROW_ON_ERROR

Is_countable

A countable chemical element in your code can be a variable with an array format or an object whose class is implementing the Countable interface.

Last year PHP 7.two added a warning that shows up whenever the web developer was counting or trying to loop an uncountable element.

It is possible to solve this problem and i of the best solutions currently used is to apply a check similar a snippet below:

if (is_array($santa) || $santa instanceof Countable) {
// $santa is countable
}

The code checks whether the variable is an array or is an instance of the Countable interface.

And information technology will work simply it seems a little bit "crowded" and as many of you lot that work long hours, after a while seeing this kind of lines wear your eyes out.

The team that is developing the new version took account of this and added a new role that volition assistance the web developer immensely.

The is_countable function takes a variable as a parameter and and so render a boolean depending if the office is countable or not.

There is no restriction about the format the parameter has to be, of course, if you put a non-countable variable the return will be imitation.

Let'due south come across it in practice

if (is_countable($santa)) {
// $santa is countable
}

This snippet basically does the same thing of the previous one simply is much more than easy to think and near important for me more readable.

Not to mention you tin use this function as shown or in a ternary conditional operator which volition look even more satisfying.

For more than data about is_countable take a look at the official RFC

array_key_first(), array_key_last()

As per version 5.6 of PHP, there are over 75 built-in functions that belong to the arrays' category.

Despite the vast numbers of tools available, at the moment, if we need to retrieve the outset or the concluding cardinal of an array nosotros have to go all the keys using array_keys() and simply and then go for the first or last values of the assortment.

Another way is to opt for cease() or reset().

As you may know, all the methods just described modifying the array pointer, which is something that (other than be resources consumer) y'all but may non desire to do.

The RFC of the upcoming version proposed the introduction of 4 brand-new methods the were fix to solve this outcome.

The four methods were:

  • array_key_first()
  • array_key_last()
  • array_value_first()
  • array_value_last()

Among the iv of them, only the one gear up that fetches the keys were accepted with 18 to xiv votes.

They work for both numeric and associative arrays.

Here is some example of a numeric one:

                $start                = array_key_first($reindeers); // $first is equal to one              
                $last                = array_key_last($reindeers); // $last is equal to 9              

This instead is an example of an associative array:

                $first                = array_key_first($reindeers); // $kickoff is equal to "Rudolph"              
                $last                = array_key_last($reindeers); // $last is equal to "Blitzen"              

The same would take worked for the other two functions illustrated in this chapter array_value_*

Just to exist articulate, let me echo,

Those functions have been refused with eighteen no and fifteen yes.

In my stance, these two functions would have been useful also merely co-ordinate to several web developers, in certain cases, the value returned would have been ambiguous.

Here is why:

                $first                = array_value_first($reindeers                ); // $first is equal to null              
                $last                = array_value_last($reindeers                );// $last is equal to null              

An additional option that I come across browsing on forums and talking to other web developers was to return a tuple like [$key => $value].

Even though this option volition not be bachelor on the new version, seeing the favourable responses, it might get in with the post-obit RFCs.

Since this is a function that did not exist before at that place are not going to exist whatsoever backwards compatibility problems, the only issue could arrive if yous have created and you lot are using your ain version of array_key_first() and array_key_last().

Same site cookie

Deploy secure application must ever be the main focus of every programmer.

One task that each of the states is facing of daily basis it to diminish the gamble of CSRF and information leakage attacks.

Same-site cooking declares that cookies must be sent only with request initiated from the same domain.

This is not an official standard just Google Chrome and several of the best PHP frameworks already implement information technology whereas Firefox and new version of other frameworks confirmed that they are planning to do and then.

Here is the support schema for same site cookie from caniuse.com

Currently,

cookies are issued past the fix-cookie header,

A spider web developer can set a key-value pair alongside flags for the browser in order to agree if a cookie should exist bachelor or not.

This manner to practise things allows a vulnerable access to CSRF attacks.

The new RFC adds is suppose to solve the problem is a non-breaking mode by adding a new parameter and besides modify four primary functions of the language.

  • setcookie
  • setrawcookie
  • session_set_cookie_params
setcookie($name [,$value [,$expire [,$path [,$domain [, $secure [,$httponly [,$samesite]]]]]]]);

2 ways were proposed.

Adding a new argument to the role or allowing an assortment of pick for moving all the options of the cookies inside.

How it will piece of work?

Two values can exist added to the same site flag nowadays in the above functions

They are Lax and Strict.

Cookies that are using Lax will exist accessible in a GET request that comes from another domain, while on the contrary Strict will non exist accessible in a Get asking.

For example, the header when using a more loose flag will look like this:

Set-Cookie: key=value; path=/; domain=example.org; HttpOnly; SameSite=Lax

Include features that Increment security in the lawmaking seem ever a no-brainer but as ever earlier deciding to apply them in our scripts we need to properly evaluate the pro and the cons of our choices

The main risk implied for using the same site flag as a supplementary statement to those functions is that it might never become an official standard.

Information technology means that eventually browser will downturn the flag.

If this happens and you have already implemented it, it volition upshot in you applications stuffed with junk lawmaking that need to be removed.

My personal advice is to wait to encounter what is going to happen.

If this flag will become more used and somewhen defined every bit a standard go for information technology!

Speaking of backward changes, like almost of the previous changes seen in this article at that place volition be no problem when implementing it in your code.

Determination

As I anticipated this new release does not involve breaking changes,

since it'due south non a new version, information technology's correct this way.

PHP is taking small but continuous steps that allow it to progress and improve over time despite the fact that over the years people accept changed to more than trendy programming languages.

In the adjacent post, yous will see other miscellaneous changes and a listing of features no longer in utilize that has finally been deprecated to make room for new projects.

If the content of these posts you liked and you do non want to look, the consummate commodity in a single format is available as a kindle on Amazon in the link below.

This blog mail service is a section of the Kindle volume " PHP seven.iii and its Christmas gifts "

Now It'south Your Plough

Now I want to hear from you:

Are you happy with the new feature brought by the language?
What are you going to use more often?

Let me know by leaving a quick comment beneath.

Tags

# php# php-73# php-new-features# iscountable# arrayfirstkey

Related Stories

lefflerconifice.blogspot.com

Source: https://hackernoon.com/new-features-of-php-7-3-complete-guide-49d254e43ee1

0 Response to "Warning in .librariesclassesdbidbimysqli.php#213 Mysqli_query(): Error Reading Result Set's Header"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel