Exemple #1
0
        public PhpReference PeekReferenceUnchecked(int i)
        {
            object          item = Items[Top - i];
            PhpReference    result;
            PhpRuntimeChain php_chain;

            // the caller may not pushed a reference although the formal argument is a reference:
            // it doesn't matter if called by callback:
            if ((result = item as PhpReference) == null)
            {
                // caller may have pushed a runtime chain => evaluate it:
                if ((php_chain = item as PhpRuntimeChain) != null)
                {
                    // call state has to be stored since chain can call arbitrary user code:
                    CallState call_state = SaveCallState();
                    result = php_chain.GetReference(Context);
                    RestoreCallState(call_state);
                }
                else
                {
                    // the reason of copy is not exactly known (it may be returning by copy as well as passing by copy):
                    result = new PhpReference(PhpVariable.Copy(item, CopyReason.Unknown));

                    // Reports an error in the case that we are not called by callback.
                    // Although, this error is fatal one can switch throwing exceptions off.
                    // If this is the case the afterwards behavior will be the same as if callback was called.
                    if (!Callback)
                    {
                        // warning (can invoke user code => we have to save and restore callstate):
                        CallState call_state = SaveCallState();

                        PhpException.ArgumentNotPassedByRef(i, CalleeName);
                        RestoreCallState(call_state);
                    }
                }
            }
            return(result);
        }