|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #9507 Java objects as session variable
Submitted: 2001-03-01 04:30 UTC Modified: 2003-08-15 21:32 UTC
Avg. Score:3.0 ± 1.3
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: geograf at geograf dot pt Assigned:
Status: Suspended Package: Feature/Change Request
PHP Version: 4.2.0 OS: ANY
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: geograf at geograf dot pt
New email:
PHP Version: OS:


 [2001-03-01 04:30 UTC] geograf at geograf dot pt

I'm trying to save a Java class into a 
session variable like the code bellow: 

if ( !session_is_registered( "objJC" ) ) 
$objJC = null; 
$objJC = new Java( "JavaClass" ); 
session_register( "objJC" ); 

This code works for the 1st time, when the 
session var 'objJC' is registered for the 1st time. All the methods of the java class can be accessed. 
The next times the variable 'objJC' already exists, as a session var, but i cannot access the methods inside, and gives me the 
error message like: 

Warning: java.lang.NoSuchMethodException: doinitmapj in c:\program files\apache group\apache\htdocs\php\php_mapxt.php on line 71 

When you do this with a normal PHP class, using include() or required( ), everything works ok. 
It seems that the registration doesn't keep the class type as a Java Class. 

Can someone help me with this? 
Than you very much in advance. 
Carlos Figueiredo 


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2001-06-22 02:22 UTC]

  if (!session_is_registered("system")) {
    $system = null;
    $system = new Java("java.lang.System");

  print $system->getProperty("java.version");

The above code works upon first request, but gives a 

  Warning: java.lang.NullPointerException in 
  e:\server\htdocs\test.php on line 10

in subsequent requests.

After commenting out the session_start() call it works fine, which is weird IMHO since session_register() implictly calls session_start().

Tested with PHP 4.0.7-dev (latest CVS), Java 2 SDK 1.3, Java HotSport Server VM 2.0.

 [2002-02-24 06:08 UTC]
Please test with  PHP 4.1.1+JDK 1.2 and report the result back 
Please do not forget  updating PHP version. Thanks.
 [2002-02-26 23:30 UTC]
Ok since Java is an incomplete class it can't be searlized currently. 
$java = new Java("java.lang.System");
echo serialize($java);
prints O:4:"java":1:{i:0;i:1;}

so if this functionality is really needed one of two things needs to happen.

1) the java class has a __wakeup and __sleep functions that keeps around the constructor arguments and makes a new object on each unseralize. Not really gaining much functionality here. cause you can just make the java object yourself without using it as a session.

2) make the java class use __wakeup and __sleep functions that acually call the java seralize and unseralize functions.. take that data and write it out with the php seralized data.

Personally i would like to see number 2 work. It would be pretty nice. I have already thought of doing this. I just need to get around to do it. Just changing the java extension isn't gunna do it. We need to change call_user_function() to call incomplete objects. I have alredy written this code i just need to apply it.

- Brad
 [2002-02-27 00:23 UTC]
Brad is right :)
We cannot do anything other than using   __wakeup and __sleep.

Status = Suspended

PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Fri Oct 22 03:03:34 2021 UTC