예제 #1
0
파일: Errors.cs 프로젝트: xmaxmex/Phalanger
 public static void InvalidImplicitCast(object argument, string targetType, string functionName)
 {
     Throw(PhpError.Warning, CoreResources.GetString("invalid_implicit_cast",
                                                     PhpVariable.GetTypeName(argument),
                                                     targetType,
                                                     functionName));
 }
예제 #2
0
        /// <summary>
        /// Prints a content of the given variable and its type.
        /// </summary>
        /// <param name="output">The output text stream.</param>
        /// <param name="obj">The variable to be printed.</param>
        public static void Dump(TextWriter output, object obj)
        {
            string        s;
            IPhpPrintable printable;

            if ((printable = obj as IPhpPrintable) != null)
            {
                printable.Dump(output);
            }
            else if ((s = obj as string) != null)
            {
                output.WriteLine(TypeNameString + "({0}) \"{1}\"", s.Length, s);
            }
            else if (obj is double)
            {
                output.WriteLine(TypeNameFloat + "({0})", Convert.DoubleToString((double)obj));
            }
            else if (obj is bool)
            {
                output.WriteLine(TypeNameBool + "({0})", (bool)obj ? True : False);
            }
            else if (obj is int)
            {
                output.WriteLine(TypeNameInt + "({0})", (int)obj);
            }
            else if (obj is long)
            {
                output.WriteLine(TypeNameLongInteger + "({0})", (long)obj);
            }
            else if (obj == null)
            {
                output.WriteLine(PhpVariable.TypeNameNull);
            }
            else
            {
                output.WriteLine("{0}({1})", PhpVariable.GetTypeName(obj), obj.ToString());
            }
        }
예제 #3
0
 /// <summary>
 /// Returns a name of declaring type.
 /// </summary>
 /// <returns>The name.</returns>
 public string GetTypeName()
 {
     return(PhpVariable.GetTypeName(value));
 }
예제 #4
0
파일: Errors.cs 프로젝트: xmaxmex/Phalanger
        /// <summary>
        /// Reports an error when a variable should be PHP object but it is not.
        /// </summary>
        /// <param name="reference">Whether a reference modifier (=&amp;) is used.</param>
        /// <param name="var">The variable which was misused.</param>
        /// <exception cref="PhpException"><paramref name="var"/> is <see cref="PhpArray"/> (Warning).</exception>
        /// <exception cref="PhpException"><paramref name="var"/> is scalar type (Warning).</exception>
        /// <exception cref="PhpException"><paramref name="var"/> is a string (Warning).</exception>
        public static void VariableMisusedAsObject(object var, bool reference)
        {
            Debug.Assert(var != null);

            if (var is PhpArray)
            {
                PhpException.Throw(PhpError.Warning, CoreResources.GetString("array_used_as_object"));
            }
            else if (PhpVariable.IsString(var))
            {
                PhpException.Throw(PhpError.Warning, CoreResources.GetString(reference ? "string_item_used_as_reference" : "string_used_as_object"));
            }
            else
            {
                PhpException.Throw(PhpError.Warning, CoreResources.GetString("scalar_used_as_object", PhpVariable.GetTypeName(var)));
            }
        }
예제 #5
0
파일: Errors.cs 프로젝트: xmaxmex/Phalanger
        /// <summary>
        /// Reports an error when a variable should be PHP array but it is not.
        /// </summary>
        /// <param name="reference">Whether a reference modifier (=&amp;) is used.</param>
        /// <param name="var">The variable which was misused.</param>
        /// <exception cref="PhpException"><paramref name="var"/> is <see cref="PhpArray"/> (Warning).</exception>
        /// <exception cref="PhpException"><paramref name="var"/> is scalar type (Warning).</exception>
        /// <exception cref="PhpException"><paramref name="var"/> is a string (Warning).</exception>
        public static void VariableMisusedAsArray(object var, bool reference)
        {
            Debug.Assert(var != null);

            DObject obj;

            if ((obj = var as DObject) != null)
            {
                PhpException.Throw(PhpError.Warning, CoreResources.GetString("object_used_as_array", obj.TypeName));
            }
            else if (PhpVariable.IsString(var))
            {
                PhpException.Throw(PhpError.Warning, CoreResources.GetString(reference ? "string_item_used_as_reference" : "string_used_as_array"));
            }
            else
            {
                PhpException.Throw(PhpError.Warning, CoreResources.GetString("scalar_used_as_array", PhpVariable.GetTypeName(var)));
            }
        }