Life time of Objects in WordPress

I have previously asked about life time of objects on stackoverflow and came to know that they exist until the end of script, i tested it and it was true. But in case of wordpress the Objects life for a longer time. Like the user object, i can access it on any page and on any script even if it is not instantiated on that particular script.

What is the reason behind that?

Related posts

Leave a Reply

1 comment

  1. The reason is, that in fact you have two objects. The data of the user comes from the database and if the user is logged in, the API functions of wordpress will give you an object with the data from the database.

    As the data from the database has not changed, you can get a quadrillion user objects on a quadrillion pages. However each of these objects lives only for one request or until unset.

    To have user objects on any page available, wordpress is storing the data of each user into the database. The database keeps the data for a longer time.