Search code examples
phpoopobjectpage-refresh

Object Oriented Programming with PHP: Refreshing Kills my Objects


I have been poking around in PHP for OOP and I noticed something... Objects are re-instantiated each time the page is refreshed. The problem is that I want the object to keep certain information in class variables for the whole time that someone is on a website.

  1. Is there some sort of way to keep an object alive the whole time that someone is surfing on the website?
  2. What alternatives are there to my problem?

It would be really helpful to have example too!


Solution

  • PHP isn't stateful. Every page load is a one time event. You can persist data with sessions, or by storing information in a database.