Exemple #1
0
        public static object InvokeMethodDynamic(string moduleName, string className, string methodName, PhpObject self,
            PhpStack stack, int[] refInfo)
        {
            int arg_count = stack.ArgCount;
            object[] args = new object[arg_count];
            PhpReference[] references = new PhpReference[arg_count];

            // convert arguments on calling stack into the args array
            stack.CalleeName = methodName;
            int ref_ptr = (refInfo != null && refInfo.Length > 0 ? 0 : -1);
            for (int i = 0; i < arg_count; i++)
            {
                if (ref_ptr >= 0)
                {
                    if (i == refInfo[ref_ptr])
                    {
                        args[i] = references[i] = stack.PeekReferenceUnchecked(i + 1);
                        if (++ref_ptr >= refInfo.Length) ref_ptr = -1;
                        continue;
                    }
                    else if (refInfo[ref_ptr] == -1)
                    {
                        args[i] = references[i] = stack.PeekReferenceUnchecked(i + 1);
                        continue;
                    }
                }
                args[i] = stack.PeekValueUnchecked(i + 1);
            }
            stack.RemoveFrame();

            if (refInfo == null || refInfo.Length == 0)
            {
                return InvokeMethod(moduleName, className, methodName, self, stack.Context, ref args, null);
            }
            else
            {
                object ret_val = InvokeMethod(moduleName, className, methodName, self, stack.Context, ref args, refInfo);

                // propagate back byref parameters
                for (int i = 0; i < arg_count; i++)
                {
                    if (references[i] != null) references[i].Value = args[i];
                }

                return ret_val;
            }
        }