1 29 30 package com.caucho.quercus.expr; 31 32 import com.caucho.quercus.Location; 33 import com.caucho.quercus.env.Env; 34 import com.caucho.quercus.env.StringValue; 35 import com.caucho.quercus.env.StringValueImpl; 36 import com.caucho.quercus.env.Value; 37 38 41 public class ToStringExpr extends UnaryExpr { 42 public ToStringExpr(Location location, Expr expr) 43 { 44 super(location, expr); 45 } 46 47 public ToStringExpr(Expr expr) 48 { 49 super(expr); 50 } 51 52 public static Expr create(Expr expr) 53 { 54 if (expr.isString()) 55 return expr; 56 else 57 return new ToStringExpr(expr); 58 } 59 60 67 public Value eval(Env env) 68 { 69 Value value = _expr.eval(env).toValue(); 70 71 if (value instanceof StringValue) 72 return value; 73 else 74 return new StringValueImpl(value.toString()); 75 } 76 77 public String toString() 78 { 79 return "((string) " + _expr + ")"; 80 } 81 } 82 83 | Popular Tags |