protected override PhpValue InvokeError(Context ctx, PhpValue[] arguments) { ResolveType(ctx, out var tinfo, out _); if (tinfo != null) { PhpException.UndefinedMethodCalled(tinfo.Name, _method); } else { throw PhpException.ClassNotFoundException(_obj.ToString(ctx)); } return(PhpValue.Void); }
/// <summary> /// Called by runtime when it expects that given type is declared. /// If not, autoload is invoked and if the type mismatches or cannot be declared, an exception is thrown. /// </summary> /// <typeparam name="T">Type which is expected to be declared.</typeparam> public void ExpectTypeDeclared <T>() { void EnsureTypeDeclared() { var tinfo = TypeInfoHolder <T> .TypeInfo; // perform regular load with autoload if (tinfo != GetDeclaredTypeOrThrow(tinfo.Name, true)) { throw PhpException.ClassNotFoundException(tinfo.Name); } } // NOTE: app-types should not be checked using ExpectTypeDeclared<T> method, compiler knows that if (!IsUserTypeDeclared(TypeInfoHolder <T> .TypeInfo)) { EnsureTypeDeclared(); } }
/// <summary> /// Creates an instance of a type dynamically with constructor overload resolution. /// </summary> /// <param name="caller"> /// Class context for resolving constructors visibility. /// Can be <c>default(<see cref="RuntimeTypeHandle"/>)</c> to resolve public constructors only.</param> /// <param name="classname">Full name of the class to instantiate. The name uses PHP syntax of name separators (<c>\</c>) and is case insensitive.</param> /// <param name="arguments">Arguments to be passed to the constructor.</param> /// <returns>The object instance.</returns> /// <exception cref="InvalidOperationException">If the class is not declared.</exception> public object Create([ImportCallerClass] RuntimeTypeHandle caller, string classname, params PhpValue[] arguments) { var tinfo = this.GetDeclaredType(classname, true) ?? throw PhpException.ClassNotFoundException(classname); return(Create(caller, tinfo, arguments)); }