1) Suppose I have 2 php files: fileA.php, and fileB.php And I have 1 class file: myClassFile.php
in fileA.php, I need to instantiate a MyClass class in myClassFile.php:
...
myObject = new MyClass();
...
in fileB.php, I need to use the myObject object created in fileA.php.
How would I do that? Is using sessions the way to go?
$_SESSION["my_object"] = myObject;
or are there better ways? Specifically, how will it be implemented?
2) Suppose I don't use solutions similar to the above.. Will myObject in fileA.php be lost (destroyed, or freed) when the user proceeds to fileB.php? That is, will there be no more reference to myObject in fileB.php?
myObjectwill be lost unless you store it somewhere (session, log file, or anywhere else). now about the first question, why would you wanna do that? and why dont you create a common php file, where you can call the class and it will be available on every page.