use of php.runtime.lang.IObject in project jphp by jphp-compiler.
the class ObjectInvokeHelper method invokeMethod.
public static Memory invokeMethod(Memory object, String methodName, String methodLowerName, Environment env, TraceInfo trace, Memory[] args) throws Throwable {
object = object.toValue();
Memory[] passed = null;
boolean doublePop = false;
if (object.type != Memory.Type.OBJECT) {
env.error(trace, ErrorType.E_RECOVERABLE_ERROR, Messages.ERR_CANNOT_CALL_OF_NON_OBJECT.fetch(methodName));
return Memory.NULL;
}
IObject iObject = ((ObjectMemory) object).value;
ClassEntity clazz = iObject.getReflection();
MethodEntity method;
if (methodName == null) {
method = clazz.methodMagicInvoke;
} else {
method = clazz.findMethod(methodLowerName);
if (method != null && method.isContextDepends()) {
ClassEntity context = env.getLastClassOnStack();
if (context != null) {
MethodEntity contextMethod = context.findMethod(methodLowerName);
if (contextMethod != null) {
method = contextMethod;
}
}
}
if (method == null && ((method = clazz.methodMagicCall) != null)) {
clazz.methodMagicCall.setModifier(Modifier.PUBLIC);
passed = new Memory[] { new StringMemory(methodName), ArrayMemory.of(args) };
doublePop = true;
}
}
String className = clazz.getName();
if (method == null) {
if (methodName == null)
methodName = "__invoke";
env.error(trace, ErrorType.E_ERROR, Messages.ERR_CALL_TO_UNDEFINED_METHOD.fetch(className + "::" + methodName));
return Memory.NULL;
}
InvokeHelper.checkAccess(env, trace, method);
if (passed == null) {
passed = InvokeHelper.makeArguments(env, args, method.getParameters(args == null ? 0 : args.length), className, methodName, trace);
}
Memory result = method.getImmutableResult();
if (result != null) {
return result;
}
try {
if (trace != null) {
String staticClass = className;
if (iObject instanceof Closure) {
staticClass = ((Closure) iObject).getScope();
}
String stackClass = clazz.isHiddenInCallStack() ? staticClass : method.getClazz().getName();
env.pushCall(trace, iObject, args, methodName, stackClass, staticClass);
if (doublePop) {
env.pushCall(trace, iObject, passed, method.getName(), stackClass, staticClass);
}
}
return method.invokeDynamic(iObject, env, passed);
} catch (NoClassDefFoundError e) {
throw new CriticalException("Unable to call method " + className + "::" + methodName + "(), " + e.getMessage());
} finally {
if (trace != null) {
env.popCall();
if (doublePop)
env.popCall();
}
}
}
use of php.runtime.lang.IObject in project jphp by jphp-compiler.
the class ObjectInvokeHelper method GetAndDecProperty.
public static Memory GetAndDecProperty(Memory object, String property, Environment env, TraceInfo trace, PropertyCallCache callCache, int cacheIndex) throws Throwable {
IObject iObject = fetchObject(object, property, env, trace);
if (iObject == null)
return Memory.NULL;
ReferenceMemory ref = new ReferenceMemory();
iObject.getReflection().minusProperty(env, trace, iObject, property, Memory.CONST_INT_1, ref);
return ref.value;
}
use of php.runtime.lang.IObject in project jphp by jphp-compiler.
the class ObjectInvokeHelper method getRefProperty.
public static Memory getRefProperty(Memory object, String property, Environment env, TraceInfo trace, PropertyCallCache callCache, int cacheIndex) throws Throwable {
object = object.toValue();
if (!object.isObject()) {
env.error(trace, Messages.ERR_CANNOT_GET_PROPERTY_OF_NON_OBJECT.fetch(property));
return Memory.NULL;
}
IObject iObject = ((ObjectMemory) object).value;
return iObject.getReflection().getRefProperty(env, trace, iObject, property, callCache, cacheIndex);
}
use of php.runtime.lang.IObject in project jphp by jphp-compiler.
the class ObjectInvokeHelper method unsetProperty.
public static void unsetProperty(Memory object, String property, Environment env, TraceInfo trace, PropertyCallCache callCache, int cacheIndex) throws Throwable {
object = object.toValue();
if (!object.isObject()) {
env.error(trace, Messages.ERR_CANNOT_GET_PROPERTY_OF_NON_OBJECT.fetch(property));
}
IObject iObject = ((ObjectMemory) object).value;
iObject.getReflection().unsetProperty(env, trace, iObject, property, callCache, cacheIndex);
}
use of php.runtime.lang.IObject in project jphp by jphp-compiler.
the class ObjectInvokeHelper method emptyProperty.
public static Memory emptyProperty(Memory object, String property, Environment env, TraceInfo trace, PropertyCallCache callCache, int cacheIndex) throws Throwable {
object = object.toValue();
if (!object.isObject()) {
return Memory.NULL;
//env.error(trace, Messages.ERR_CANNOT_GET_PROPERTY_OF_NON_OBJECT.fetch(property));
}
IObject iObject = ((ObjectMemory) object).value;
return iObject.getReflection().emptyProperty(env, trace, iObject, property);
}
Aggregations