Bug #9162 Updated: Java support corrupts Hashtables

From: Date: Mon, 25 Mar 2002 05:00:02 +0000
Subject: Bug #9162 Updated: Java support corrupts Hashtables
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-3247@lists.php.net to get a copy of this message
ID: 9162 Updated by: php-bugs@lists.php.net Reported By: freifeld@turbogenomics.com -Status: Feedback +Status: No Feedback Bug Type: Java related Operating System: Linux, RH6.2 PHP Version: 4.0.4pl1 New Comment: No feedback was provided for this bug for over a month, so it is being suspended automatically. If you are able to provide the information that was originally requested, please do so and change the status of the bug back to "Open". Previous Comments: ------------------------------------------------------------------------ [2002-02-24 06:04:38] yohgaki@php.net Please test with PHP 4.1.1+JDK 1.2 and report back Thanks. ------------------------------------------------------------------------ [2001-02-08 10:58:27] freifeld@turbogenomics.com Just in case you were confused, the java method getSomething() should return (String) myhash.get( "myname" ), and the PHP call should be my_java->getSomething( $my_hash ). You get the idea. ------------------------------------------------------------------------ [2001-02-07 15:28:44] freifeld@turbogenomics.com This bug is with the Java support in PHP4. PHP seems to try to treat Java Hashtable objects as PHP-native arrays, with several negative impacts. First of all, Java Hashtables have no internal concept of ordering or null termination, nor do they have an internal "current" pointer. Therefore, if you try to travserse a Java Hashtable as you would a PHP array, you will run off the end! However, since the Hashtable is not an object (under PHP), you cannot call $my_hash->get( "x" ) or $my_hash->put( "y" ). Second of all, if you try to pass such a Hashtable BACK to a Java class method, you will find that the Hashtable has been corrupted, and all your datatypes changed and you will get various NullPointerExceptions or illegal cast exceptions. It seems to me the most natural approach at this point would be to just treat Java Hashtables as generic objects, and therefore retain the get() and put() methods. That way you don't corrupt the Hashtable, and you don't let anyone go off the end of any arrays. I don't know if this kind of thing happens with other Java object classes. There is a workaround whereby one can, in Java, explicitly repair a corrupted Hashtable, but that is pretty ugly. If you are interested in looking at the workaround, email me. Here is a code snippet illustrating what I mean: MyClass.java: public class MyClass { public MyClass() { } public Hashtable makeHash( int ikey, int ival, String skey, String sval ) { Hashtable myhash = new Hashtable(); myhash.put( ikey, ival ); myhash.put( skey, sval ); myhash.put( "myname", "joe" ); return myhash; } public String getSomething( Hashtable myhash ) { return myhash.get( "myname" ); } } MyPage.php <? $my_java = new Java( "MyClass" ); $my_hash = my_java->makeHash( 1,2,"yourname", "steve" ); // watch this: print( implode( ",", $my_hash ) ); // explosion! off the end of the array // or, print( $my_java->getSomething() ); // java exception! ?> ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=9162&edit=1

« previous php.bugs (#3247) next »