use of php.runtime.memory.ArrayMemory in project jphp by jphp-compiler.
the class InfoFunctions method get_defined_functions.
public static Memory get_defined_functions(Environment env) {
ArrayMemory array = new ArrayMemory();
ArrayMemory item = (ArrayMemory) array.refOfIndex("internal").assign(new ArrayMemory());
for (FunctionEntity entity : env.getFunctions()) {
if (entity.isInternal())
item.add(new StringMemory(entity.getName()));
}
item = (ArrayMemory) array.refOfIndex("user").assign(new ArrayMemory());
for (FunctionEntity entity : env.getLoadedFunctions().values()) {
if (!entity.isInternal())
item.add(new StringMemory(entity.getName()));
}
return array.toConstant();
}
use of php.runtime.memory.ArrayMemory in project jphp by jphp-compiler.
the class LangFunctions method property_exists.
public static Memory property_exists(Environment env, Memory clazz, String property) throws Throwable {
ClassEntity classEntity;
IObject object = null;
boolean isMagic = false;
if (clazz.isObject()) {
ObjectMemory tmp = clazz.toValue(ObjectMemory.class);
classEntity = tmp.getReflection();
object = tmp.value;
} else {
String name = clazz.toString();
String nameL = name.toLowerCase();
classEntity = env.fetchClass(name, nameL, true);
if (classEntity == null) {
classEntity = env.fetchMagicClass(name, nameL);
isMagic = true;
}
}
if (classEntity == null) {
return Memory.FALSE;
}
if (object != null) {
ArrayMemory props = object.getProperties();
ClassEntity context = env.getLastClassOnStack();
PropertyEntity entity = classEntity.isInstanceOf(context) ? context.properties.get(property) : classEntity.properties.get(property);
int accessFlags = entity == null ? 0 : entity.canAccess(env);
if (accessFlags != 0)
return Memory.FALSE;
return (props != null && props.getByScalar(entity == null ? property : entity.getSpecificName()) != null) ? Memory.TRUE : Memory.FALSE;
} else {
PropertyEntity entity = classEntity.properties.get(property);
if (isMagic) {
int accessFlags = entity == null ? 0 : entity.canAccess(env);
if (accessFlags != 0)
return Memory.FALSE;
}
return entity != null ? Memory.TRUE : Memory.FALSE;
}
}
use of php.runtime.memory.ArrayMemory in project jphp by jphp-compiler.
the class LangFunctions method debug_backtrace.
public static Memory debug_backtrace(Environment env, TraceInfo trace, int options, int limit) {
boolean provideObject = (options & LangConstants.DEBUG_BACKTRACE_PROVIDE_OBJECT) == LangConstants.DEBUG_BACKTRACE_PROVIDE_OBJECT;
boolean ignoreArgs = (options & LangConstants.DEBUG_BACKTRACE_IGNORE_ARGS) == LangConstants.DEBUG_BACKTRACE_IGNORE_ARGS;
ArrayMemory result = new ArrayMemory();
for (int i = 0; i < env.getCallStackTop(); i++) {
if (limit != 0 && i >= limit)
break;
CallStackItem item = env.peekCall(i);
ArrayMemory el = item.toArray(provideObject, ignoreArgs);
result.add(el);
}
return result.toConstant();
}
use of php.runtime.memory.ArrayMemory in project jphp by jphp-compiler.
the class LangFunctions method get_class_vars.
public static Memory get_class_vars(Environment env, TraceInfo trace, Memory value) {
ClassEntity entity;
if (value.isString()) {
entity = env.fetchClass(value.toString(), true);
} else if (value.isObject()) {
entity = value.toValue(ObjectMemory.class).getReflection();
} else {
env.warning(trace, "get_class_vars(): Argument 1 must be string or object, %s given", value.getRealType().toString());
return Memory.NULL;
}
if (entity == null)
return Memory.NULL;
ClassEntity context = env.getLastClassOnStack();
ArrayMemory result = new ArrayMemory();
for (PropertyEntity el : entity.getProperties()) {
if (el.canAccess(env, context) == 0)
result.refOfIndex(el.getName()).assign(el.getDefaultValue(env));
}
for (PropertyEntity el : entity.getStaticProperties()) {
if (el.canAccess(env, context) == 0)
result.refOfIndex(el.getName()).assign(el.getDefaultValue(env));
}
return result.toConstant();
}
use of php.runtime.memory.ArrayMemory in project jphp by jphp-compiler.
the class LangFunctions method error_get_last.
public static Memory error_get_last(Environment env) {
SystemMessage err = env.getLastMessage();
if (err == null)
return Memory.NULL;
ArrayMemory result = new ArrayMemory();
result.refOfIndex("type").assign(err.getType().value);
result.refOfIndex("message").assign(err.getMessage());
if (err.getTrace() != null && err.getTrace().trace != null) {
result.refOfIndex("file").assign(err.getTrace().trace.getFileName());
result.refOfIndex("line").assign(err.getTrace().trace.getStartLine() + 1);
result.refOfIndex("position").assign(err.getTrace().trace.getStartPosition() + 1);
}
return result.toConstant();
}
Aggregations