示例#1
0
        /// <summary>
        /// Evaluates this chain as if it had the <see cref="PHP.Core.AST.AccessType.ReadRef"/> access type.
        /// </summary>
        /// <param name="context">Current script context.</param>
        /// <returns>The result of chain evaluation.</returns>
        public PhpReference GetReference(ScriptContext context)
        {
            PhpReference reference;

            RuntimeChainElement element = Chain;

            if (element == null)
            {
                // if we are just wrapping the variable with a PhpReference, make a copy
                reference = Variable as PhpReference;
                if (reference == null)
                {
                    reference = new PhpReference(PhpVariable.Copy(Variable, CopyReason.Unknown));
                }

                return(reference);
            }

            // make sure that we have a PhpReference
            reference = PhpVariable.MakeReference(Variable);

            if (element == lastElement)
            {
                // GetPropertyRef/GetItemRef
                return(element.GetRef(ref reference.value, context, Caller));
            }

            // EnsureVariableIsObject/EnsureVariableIsArray
            object var = element.EnsureVariable(ref reference.value, context, Caller);

            if (var == null)
            {
                return(new PhpReference());
            }

            while (element.Next != null)
            {
                // Ensure{Field,Item}Is{Object,Array}
                var = element.Ensure(var, context, Caller);
                if (var == null)
                {
                    return(new PhpReference());
                }

                element = element.Next;
            }

            // GetObjectPropertyRef/GetArrayItemRef
            return(element.GetEnsuredRef(var, context, Caller));
        }