Why is unserialize nested inside another unserialize function in WordPress core?

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

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

First off, I don’t even understand why unserialize has been defined since its a native php function. Secondly, what in the world is going on here since its defined recursively without any condition to halt infinite recursion?

Read More

Throw me a bone. I’m newbie at this stuff.

Related posts

Leave a Reply

2 comments

  1. That’s got to be method definition in a class, eg:

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

    Otherwise you’d get a fatal error saying that you can’t redeclare unserialize().

    All it does is add an unserialize() method to a class. This method then calls the native unserialize() function in PHP. Seems rather silly, but then, I didn’t write WordPress.


    I believe I found the method in question: wp-includes/rss.php (line 783). And it’s indeed a method of the RSSCache class.

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

  2. NullUserException has it right. As far as an explanation goes, here’s my best shot.

    For example, let’s say one day PHP decides to deprecate the unserialize function. Suddenly you have to change everywhere you can find “unserialize()” in your code to a new function name, and possibly do some rewriting. However, if you use your own function such as the way WordPress does, all you have to do is change your version of the unserialize function once and not everywhere it is used.