I have instantiated a class in my index.php
file. But then I use jQuery Ajax to call some PHP files, but they can't use my object that I created in the index.php
file.
How can I make it work? Because I don´t want to create new objects, because the one I created holds all the property values I want to use.
As others have suggested,
$_SESSION
is the standard way to do it, in fact, that was one of the reasons, that sessions where invented to solve. Other options, i.e. serializing the object rely on the client side to hold the object and then return it untampered. Depending on the data in the object, it is not a good solution, as a) the object may include information that should not be available on the client side for security reasons and b) you will have to verify the object after receiving it.That said, and if you still want to use the object on the client side, then JSON is an option for serializing object data, see JSON functions in PHP.