Why is unserialize nested in another unserialize function in the Wordpress core?

I was looking through the core of Wordpress, and I found this function:

function unserialize ( $data ) { return unserialize( $data ); } 

First, I don’t even understand why unserialize was defined with its own PHP function. Secondly, what is happening here in the world, since it is defined recursively without any condition for stopping infinite recursion?

Throw me a bone. I am new to this.

+4
source share
2 answers

This should be a method definition in the class, for example:

 class SomeClass { function unserialize($data) { return unserialize($data); } // ... } 

Otherwise, you will receive a fatal error stating that you cannot update unserialize() .

All he does is add the unserialize() method to the class. This method then calls the built-in unserialize() function in PHP. It seems pretty dumb, but then, I did not write Wordpress.


I believe I found this method: wp-includes/rss.php (line 783). And this is really an RSSCache class RSSCache .

I suppose they might want to write their own serialization routine in the future, and / or some RSSCache subclass has its own serialize() and unserialize() .

+3
source

NullUserException has this right. As for the explanations, here is my best shot.

For example, let's say one day PHP decides to abandon the unserialize function. Suddenly, you will have to change wherever you can find "unserialize ()" in your code to make a new function name, and possibly do some rewriting. However, if you use your own function, such as WordPress does, all you have to do is change your version of the non-serialization function once, and not wherever it is used.

+1
source

Source: https://habr.com/ru/post/1437848/


All Articles