the same syntax. Furthermore, if the java object is of type
"java.lang.Class", then static members
- 4) Exceptions raised result in PHP warnings, and null results.
+ 4) Exceptions raised result in PHP warnings, and null results. The
+ warnings may be eliminated by prefixing the method call with an
+ "@" sign. The following experimental APIs may be used to retrieve
+ and reset the last error:
+
+ java_last_exception_get()
+ java_last_exception_clear()
+
+ These APIs are not currently implemented in a reentrant fashion.
5) Overload resolution is in general a hard problem given the
differences in types between the two languages. The PHP Java
--- /dev/null
+<?
+ $stack=new Java("java.util.Stack");
+ $stack->push(1);
+
+ #
+ # Should succeed and print out "1"
+ #
+ $result = $stack->pop();
+ $ex = java_last_exception_get();
+ if (!$ex) print "$result\n";
+
+ #
+ # Should fail - note the "@" eliminates the warning
+ #
+ $result=@$stack->pop();
+ $ex=java_last_exception_get();
+ if ($ex) print $ex->toString();
+
+ #
+ # Reset last exception
+ #
+ java_last_exception_clear();
+?>
/***************************************************************************/
+PHP_FUNCTION(java_last_exception_get)
+{
+ jlong result = 0;
+ jmethodID lastEx;
+
+ (pval*)(long)result = return_value;
+
+ lastEx = (*jenv)->GetStaticMethodID(jenv, php_reflect, "lastException",
+ "(J)V");
+
+ (*jenv)->CallStaticVoidMethod(jenv, php_reflect, lastEx, result);
+}
+
+/***************************************************************************/
+
+PHP_FUNCTION(java_last_exception_clear)
+{
+ jlong result = 0;
+ jmethodID clearEx;
+
+ (pval*)(long)result = return_value;
+
+ clearEx = (*jenv)->GetStaticMethodID(jenv, php_reflect, "clearException",
+ "()V");
+
+ (*jenv)->CallStaticVoidMethod(jenv, php_reflect, clearEx);
+}
+
+/***************************************************************************/
+
static pval _java_getset_property
(zend_property_reference *property_reference, jobjectArray value)
{
}
function_entry java_functions[] = {
+ PHP_FE(java_last_exception_get, NULL)
+ PHP_FE(java_last_exception_clear, NULL)
{NULL, NULL, NULL}
};
}
}
+ static Throwable lastException = null;
+
+ static void lastException(long result) {
+ setResult(result, lastException);
+ }
+
+ static void clearException() {
+ lastException = null;
+ }
+
static void setException(long result, Throwable e) {
if (e instanceof InvocationTargetException) {
Throwable t = ((InvocationTargetException)e).getTargetException();
if (t!=null) e=t;
}
+ lastException = e;
setException(result, e.toString().getBytes());
}
the same syntax. Furthermore, if the java object is of type
"java.lang.Class", then static members
- 4) Exceptions raised result in PHP warnings, and null results.
+ 4) Exceptions raised result in PHP warnings, and null results. The
+ warnings may be eliminated by prefixing the method call with an
+ "@" sign. The following experimental APIs may be used to retrieve
+ and reset the last error:
+
+ java_last_exception_get()
+ java_last_exception_clear()
+
+ These APIs are not currently implemented in a reentrant fashion.
5) Overload resolution is in general a hard problem given the
differences in types between the two languages. The PHP Java
--- /dev/null
+<?
+ $stack=new Java("java.util.Stack");
+ $stack->push(1);
+
+ #
+ # Should succeed and print out "1"
+ #
+ $result = $stack->pop();
+ $ex = java_last_exception_get();
+ if (!$ex) print "$result\n";
+
+ #
+ # Should fail - note the "@" eliminates the warning
+ #
+ $result=@$stack->pop();
+ $ex=java_last_exception_get();
+ if ($ex) print $ex->toString();
+
+ #
+ # Reset last exception
+ #
+ java_last_exception_clear();
+?>
/***************************************************************************/
+PHP_FUNCTION(java_last_exception_get)
+{
+ jlong result = 0;
+ jmethodID lastEx;
+
+ (pval*)(long)result = return_value;
+
+ lastEx = (*jenv)->GetStaticMethodID(jenv, php_reflect, "lastException",
+ "(J)V");
+
+ (*jenv)->CallStaticVoidMethod(jenv, php_reflect, lastEx, result);
+}
+
+/***************************************************************************/
+
+PHP_FUNCTION(java_last_exception_clear)
+{
+ jlong result = 0;
+ jmethodID clearEx;
+
+ (pval*)(long)result = return_value;
+
+ clearEx = (*jenv)->GetStaticMethodID(jenv, php_reflect, "clearException",
+ "()V");
+
+ (*jenv)->CallStaticVoidMethod(jenv, php_reflect, clearEx);
+}
+
+/***************************************************************************/
+
static pval _java_getset_property
(zend_property_reference *property_reference, jobjectArray value)
{
}
function_entry java_functions[] = {
+ PHP_FE(java_last_exception_get, NULL)
+ PHP_FE(java_last_exception_clear, NULL)
{NULL, NULL, NULL}
};
}
}
+ static Throwable lastException = null;
+
+ static void lastException(long result) {
+ setResult(result, lastException);
+ }
+
+ static void clearException() {
+ lastException = null;
+ }
+
static void setException(long result, Throwable e) {
if (e instanceof InvocationTargetException) {
Throwable t = ((InvocationTargetException)e).getTargetException();
if (t!=null) e=t;
}
+ lastException = e;
setException(result, e.toString().getBytes());
}