Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: [HELP] Java Object and PHP Session

Re: [HELP] Java Object and PHP Session

From: Andy Hassall <andy_at_andyh.co.uk>
Date: Sun, 11 Jan 2004 21:13:37 +0000
Message-ID: <8fe300le33lu436g101mldt0vili530dlv@4ax.com>


On 11 Jan 2004 11:06:54 -0800, akumpum_at_virgilio.it (Roberto) wrote:

>In a PHP page I created an instance of a Java Object then I inserted
>it in the superglobal $_Session Array:
>
>session_start();
>$frodo = new Java('Hobbit','Frodo');
>$_SESSION['frodo'] = $frodo ;
>
>the problem arise when I try to use such an object from another PHP
>page:
>
>session_start();
>$frodo = $_SESSION['frodo'];
>$frodo->getName(); // here I have NullPointerException
>
>I tried also using serialize\unserialize but still not working
>
>then I tried adding a creation of a new instance to let know PHP about
>the class definition:
>
>session_start();
>$bilbo = new Java('Hobbit','Bilbo');
>$frodo = $_SESSION['frodo'];
>
>Here I have no error but $frodo seems to be $bilbo, as a
>matter of fact i obtain "Bilbo" from the method getName and not
>"Frodo" as I
>expected:
>$frodo->getName();
>
>what to do ?

 comp.lang.php would be an on-topic newsgroup rather than those you've posted to. Followup-To set to comp.lang.php.

 In the same way you can't store PHP resource handles in a session because there's data 'behind the scenes' that gets freed at the end of the request, you (probably) also can't store Java objects. Or it could be a bug; Java support is marked as EXPERIMENTAL in the documentation. Have a look at http://bugs.php.net.

 Perhaps you could get Java itself to produce a serialised version of the object, retrieve that as raw data into a PHP variable and then store that in the session. Then on the next page, pass the data to Java to unserialise it back into an object.

-- 
Andy Hassall <andy_at_andyh.co.uk> / Space: disk usage analysis tool
<http://www.andyh.co.uk> / <http://www.andyhsoftware.co.uk/space>
Received on Sun Jan 11 2004 - 15:13:37 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US