NZ_Kiwis;11044463 wrote:So why does PHP OOP exist? what exactly is the benefit?
There is plenty of reading you could do about this if you were only to do a little searching.
OOP does not mean 'persistent objects on the server.' OOP basically means programming with objects that you describe by defining classes. OOP is essentially an advancement over old-school procedural programming. It expands the idea of what programming is and introduces new types of data and functions beyond just plain old variables, constants, and functions. Basically it introduces the idea of classes. A class lets you define a bunch of related constants, variables, and functions and wrap them up in a tidy package. Why do this? It helps with code organization by clustering related functionality together and avoiding the often mind-bending difficulty of avoiding name collisions and organizing code.
NZ_Kiwis;11044463 wrote:@ - yes I want the object to exist over two distinct HTTP requests.
As laserlight says, HTTP is a stateless protocol. Think of it as the server having amnesia. It will not remember you unless you remind it of who you are. You do this by using a session id. A session id is just some random token, usually a string of characters, that the server gives you to keep track of who is asking for what page. Every time you request a new page, you send the session id back to the server via COOKIE, GET, or POST so the server can look at it and continue from where you were during the previous request.
NZ_Kiwis;11044463 wrote:Am I better off loading my object from items stored into a DATABASE and retrieve these and create a new object on every page load?
This is in fact how most PHP web applications work. A lot of most PHP frameworks' code is devoted to re-establishing all of the code context that needs to exist in order for the code to have a consistent environment for operation. The basic idea is that every time you request a page from a PHP server, the code has to go and connect to the database, look at your session id and see if you had a prior session, and then retrieve any data relevant to your session. Whether you are 'better off' or not is going to depend on the specifics I expect. You need to be more specific about what problem you are wrestling with.
NZ_Kiwis;11044463 wrote:Can AJAX assist here? is AJAX able to send or call my class functions or procedures if it's 'include('object.php)' from my main page?
I do think AJAX can be of assistance in providing a consistent user experience, but only to a limited extent. Because JS runs on the client, AJAX functionality can be abused by malicious users if you rely on it too heavily. For instance, a clever user might change his JS variable has_administrator_privileges[/b] from FALSE to TRUE just by using a JS debugger. Your server better handle authentication properly to deny such users access to sensitive information. Basically, if it runs on the client, a bad guy can easily tamper with it.