Page 1 of 1

Please help a newbie with object passing

Posted: Tue May 22, 2007 6:51 pm
by victorsk
Hello,

I have a difficulty figuring out a way for one PHP file to get object information from another. This is my situation:

1. SOAP object is constructed in file1.php using a SOAP method call and its values are copied into $resp variable
2. file2.php has to get the $resp object's values.

I have already attempted creating a class client and instatiating its members with values obtained from SOAP calls

The problem is that in file2.php I would than have to re-create an instance of 'client' object:

file2.php
$client = new client();
$client->getClient(); // this will require complete SOAP request again which very time consuming

Please, let me know, is there a way to pass a ready-made $resp object from file1.php to file2.php without creating an instance in file2.php and calling its member functions again?

Please help,
Thank you,
Victor.

Posted: Tue May 22, 2007 7:01 pm
by Weirdan

Posted: Tue May 22, 2007 7:02 pm
by Ollie Saunders
Restrict your files to the definitions of the classes without instantiation. This way you can load classes without side-effects. Create a new file (possibly also a class) to perform the operation you need to with the other 2.

Posted: Tue May 22, 2007 7:21 pm
by victorsk
Thank you so much for replying. I just used include('file1.php') in file2.php then added var_dump($client) (variable from file1.php) and I seem to have gotten all the objects information :-) , wow, PHP is awesome. Imagine that doing with JSPs.

Thanks again,
Victor.

Posted: Tue May 22, 2007 11:54 pm
by victorsk
Hello,

Sorry all, but my excitement was too premature. I tried using above suggestions but it doesn't seem to work for my problem. Perhaps if I clarify it a bit more it will be easier to find a solution:

I need to find a way on how to save a session and an object obtained in file1.php and use the session and object information in file2.php.

I cannot create a class and then instantiante it in file2.php because I am sending a SOAP request and with it I am getting that session and object information.
There are subsequent other SOAP API functions that I need to call using session and object information obtained in file1.php so:

Step 1:
CheckAvailability (uses object obtained in file1)
onClick="load file2.php?parameter=some parameters

Step 2:
Add Product
onClick="load file3.php?parameter= some parameters" <<< uses object/session information obtained from file1 AND CheckAvailability

Step 3:
BookProduct
onclick="load file4.php?parameter=some parameters" <<< uses object/session information obtained file1 AND CheckAvailability AND Add Product

Clearly, re-using the same class at Step3 part will be extremely inefficient because I have to call every previous procedure.

I hope I clearly defined my problem so it seems like the only way is to pass a resulting object/session from file to file as opposed to getting it from step 1. So the basic Idea: at Step 3 use object's values obtained in Step1 + Step2.

Ideally, I would just need to pass session and object information as parameter to each subsequent file. But I am not sure if it is possible.

Please help,
Thank you,
Victor.

Posted: Wed May 23, 2007 1:37 am
by Ollie Saunders
Clearly, re-using the same class at Step3 part will be extremely inefficient because I have to call every previous procedure.
I'm not sure you have a choice. PHP is stateless so you either have to get the data again or cache it somewhere. Most of us just get the data again.