public static PhpArray Reverse(PhpArray array, bool preserveKeys) { if (array == null) { PhpException.ArgumentNull("array"); return null; } PhpArray result = new PhpArray(); if (preserveKeys) { // changes only the order of elements: foreach (KeyValuePair<IntStringKey, object> entry in array) result.Prepend(entry.Key, entry.Value); } else { // changes the order of elements and reindexes integer keys: int i = array.IntegerCount; foreach (KeyValuePair<IntStringKey, object> entry in array) { if (entry.Key.IsString) result.Prepend(entry.Key.String, entry.Value); else result.Prepend(--i, entry.Value); } } // if called by PHP languge then all items in the result should be inplace deeply copied: result.InplaceCopyOnReturn = true; return result; }
/// <summary> /// Returns array containing current stack state. Each item is an array representing one stack frame. /// </summary> /// <returns>The stack trace.</returns> /// <remarks> /// The resulting array contains the following items (their keys are stated): /// <list type="bullet"> /// <item><c>"file"</c> - a source file where the function/method has been called</item> /// <item><c>"line"</c> - a line in a source code where the function/method has been called</item> /// <item><c>"column"</c> - a column in a source code where the function/method has been called</item> /// <item><c>"function"</c> - a name of the function/method</item> /// <item><c>"class"</c> - a name of a class where the method is declared (if any)</item> /// <item><c>"type"</c> - either "::" for static methods or "->" for instance methods</item> /// </list> /// Unsupported items: /// <list type="bullet"> /// <item><c>"args"</c> - routine arguments</item> /// <item><c>"object"</c> - target instance of the method invocation</item> /// </list> /// </remarks> public PhpArray GetUserTrace() { int i = GetFrameCount() - 1; PhpArray result = new PhpArray(); if (i >= 1) { PhpStackFrame info_frame = GetFrame(i--); while (i >= 0) { PhpStackFrame frame = GetFrame(i); PhpArray item = new PhpArray(); // debug info may be unknown in the case of transient code: if (info_frame.Line > 0) { item["line"] = info_frame.Line; item["column"] = info_frame.Column; } item["file"] = info_frame.File; item["function"] = frame.Name; if (frame.IsMethod) { item["class"] = frame.DeclaringTypeName; item["type"] = frame.Operator; } result.Prepend(i, item); if (frame.HasDebugInfo) info_frame = frame; i--; } } return result; }