Browse Source

Merge pull request #4921 from mockey/php-reflection-fixes

Php reflection fixes
Andy Li 9 years ago
parent
commit
fbc87e2723
2 changed files with 9 additions and 13 deletions
  1. 8 6
      std/php/_std/Reflect.hx
  2. 1 7
      tests/unit/src/unitstd/Reflect.unit.hx

+ 8 - 6
std/php/_std/Reflect.hx

@@ -40,17 +40,17 @@
 		if (untyped __php__("isset($cls_vars['__properties__']) && isset($cls_vars['__properties__']['get_'.$field]) && ($field = $cls_vars['__properties__']['get_'.$field])"))
 			return untyped __php__("$o->$field()");
 		else
-			return untyped __php__("$o->$field");
+			return untyped __call__("_hx_field", o, field);
 	}
 
-	public static function setProperty( o : Dynamic, field : String, value : Dynamic ) : Void untyped {
+	public static function setProperty( o : Dynamic, field : String, value : Dynamic ) : Void {
 		if (null == o) return null;
 		var cls : String = Std.is(o, Class) ? untyped __php__("$o->__tname__") : untyped __call__("get_class", o);
 		var cls_vars : php.NativeArray = untyped __call__("get_class_vars", cls);
 		if (untyped __php__("isset($cls_vars['__properties__']) && isset($cls_vars['__properties__']['set_'.$field]) && ($field = $cls_vars['__properties__']['set_'.$field])"))
-			return untyped __php__("$o->$field($value)");
+			untyped __php__("$o->$field($value)");
 		else
-			return untyped __php__("$o->$field = $value");
+			untyped __setfield__(o, field, value);
 	}
 
 	public static function callMethod( o : Dynamic, func : haxe.Constraints.Function, args : Array<Dynamic> ) : Dynamic untyped {
@@ -86,12 +86,14 @@
 		if( v == null )
 			return false;
 		if(untyped __call__("is_object", v))
-			return untyped __php__("$v instanceof _hx_anonymous") || Type.getClass(v) != null;
+			return untyped __php__("$v instanceof _hx_anonymous") || Type.getClass(v) != null
+			  || untyped __php__("$v instanceof _hx_class")
+			  || untyped __php__("$v instanceof _hx_enum");
 		return untyped __php__("is_string($v) && !_hx_is_lambda($v)");
 	}
 
 	public static function isEnumValue( v : Dynamic ) : Bool {
-		return untyped __php__("$v instanceof _hx_enum");
+		return untyped __php__("$v instanceof Enum");
 	}
 
 	public static function deleteField( o : Dynamic, field : String ) : Bool {

+ 1 - 7
tests/unit/src/unitstd/Reflect.unit.hx

@@ -1,4 +1,3 @@
-#if !php
 // hasField
 var x = { a: 1, b: null };
 Reflect.hasField(x, "a") == true;
@@ -36,7 +35,7 @@ c.v == "bar";
 var c = new C2();
 Reflect.getProperty(c, "v") == "var";
 Reflect.getProperty(c, "prop") == "prop";
-//Reflect.getProperty(c, "func")() == "foo";
+Reflect.getProperty(c, "func")() == "foo";
 Reflect.getProperty(c, "propAcc") == "1";
 //Reflect.getProperty(null, "a") == null;
 //Reflect.getProperty(null, null) == null;
@@ -49,10 +48,6 @@ Reflect.field(x, "c") == "foo";
 var c = new C2();
 Reflect.setProperty(c, "v", "bar");
 c.v == "bar";
-//Reflect.setProperty(c, "v2", "bar2");
-//c.v2 == "bar";
-//Reflect.setProperty(c, "func2", function() return "x");
-//Reflect.field(c, "func2")() == "x";
 Reflect.setProperty(c, "propAcc", "abc");
 #if !as3
 // not supported on AS3
@@ -154,4 +149,3 @@ Reflect.isEnumValue(true) == false;
 Reflect.isEnumValue(null) == false;
 var x:C = null;
 Reflect.isEnumValue(x) == false;
-#end