From: Jost B. <jos...@ya...> - 2005-01-31 18:32:28
|
Hi, > public NameValue[] process_context > $nameValues = $activity->process_context(); > So far I couldn't figure out a way how to iterate through all the > elements of the returned array in PHP. $Array = new java_class("java.lang.reflect.Array"); for($i=0; $i<$Array->getLength($nameValues); $i++) echo $nameValues[i] . "\n"; should work if you have PHP5 (please see tests.php5/arrayInterface.php). In PHP4 the bridge uses the same method as the ext/java: it copies all elements from the java array into a PHP hashtable $nameValues. I don't know at the moment how it is possible to ask a PHP hash table for its length. > It seems not possible to access the java.length property '$nameValues->length' The bridge accesses java via reflection. For some reasons Sun decided to wrap arrays differently (via a separate java.lang.reflect.Array interface). > 'foreach ($nameValues as $value) { echo "soemthing" }' work. This should work in both PHP4 and PHP5, please see tests.php5/iteratorInterface.php. The example uses a Map, but getPhpMap() works for Arrays, Maps and Collections. Can you please set the log level to debug and send the result? I am looking for the output of: logDebug("returning map for "+ value.getClass()); > Do I need to modify the native Java-Class so it provides another > java-interface(collection,ArrayList)? Not necessary. I think that for some reason the value is neither an Array, nor a Map or Collection. We'll see. Jost |