new public static void GetObjectData(DObject /*!*/ instance, SerializationInfo /*!*/ info, StreamingContext strctx) { info.SetType(typeof(SPLDeserializer)); SerializationContext context = SerializationContext.CreateFromStreamingContext(strctx); object res = PhpVariable.Dereference(instance.InvokeMethod("serialize", null, context.ScriptContext)); if (res == null) { // serialize returned NULL -> this instance will deserialize as NULL info.AddValue(__PHP_Incomplete_Class.ClassNameFieldName, String.Empty); } else { string res_str = PhpVariable.AsString(res); if (res_str == null) { // serialize did not return NULL nor a string -> throw an exception Library.SPL.Exception.ThrowSplException( _ctx => new Library.SPL.Exception(_ctx, true), context.ScriptContext, string.Format(CoreResources.serialize_must_return_null_or_string, instance.TypeName), 0, null); } info.AddValue(SerializedDataFieldName, res_str); info.AddValue(__PHP_Incomplete_Class.ClassNameFieldName, instance.TypeName); } }
/// <summary> /// Calls user error handler. /// </summary> /// <returns>Whether to report error by default handler (determined by handler's return value).</returns> /// <exception cref="ScriptDiedException">Error handler dies.</exception> private static bool CallUserErrorHandler(ScriptContext context, PhpError error, Func <ErrorStackInfo> info, string message) { LocalConfiguration config = context.Config; try { object result = PhpVariable.Dereference(config.ErrorControl.UserHandler.Invoke(new PhpReference[] { new PhpReference((int)error), new PhpReference(message), new PhpReference(new LazyStackInfo(info, true)), new PhpReference(new LazyStackInfo(info, false)), new PhpReference() // global variables list is not supported })); // since PHP5 an error is reported by default error handler if user handler returns false: return(result is bool && (bool)result == false); } catch (ScriptDiedException) { // user handler has cancelled the error via script termination: throw; } catch (PhpUserException) { // rethrow user exceptions: throw; } catch (Exception) { } return(false); }
/// <summary> /// Evaluates this chain as if it had the <see cref="PHP.Core.AST.AccessType.Read"/> access type. /// </summary> /// <param name="context">Current script context.</param> /// <returns>The result of chain evaluation.</returns> public object GetValue(ScriptContext context) { // dereference the PhpReference object var = PhpVariable.Dereference(Variable); RuntimeChainElement element = Chain; while (element != null) { // GetProperty/GetItem var = element.Get(var, context, Caller); element = element.Next; } return(var); }
public object PeekValueUnchecked(int i) { PhpRuntimeChain php_chain; // caller may have pushed a reference even if a formal argument is not reference => dereference it: object result = PhpVariable.Dereference(Items[Top - i]); // caller may have pushed a runtime chain => evaluate it: if ((php_chain = result as PhpRuntimeChain) != null) { // call state has to be stored since chain can call arbitrary user code: CallState call_state = SaveCallState(); result = php_chain.GetValue(Context); RestoreCallState(call_state); } return(result); }