Преглед изворни кода

[php7] do not throw on Reflect.getProperty(o, field) if field does not exist (fixes #6659, fixes 6554)

Alexander Kuzmenko пре 8 година
родитељ
комит
5369353553
4 измењених фајлова са 23 додато и 14 уклоњено
  1. 1 0
      extra/CHANGES.txt
  2. 1 0
      std/php/_std/Reflect.hx
  3. 7 0
      std/php7/Boot.hx
  4. 14 14
      std/php7/_std/Reflect.hx

+ 1 - 0
extra/CHANGES.txt

@@ -10,6 +10,7 @@ xxxx-xx-xx: 3.4.3
 	php7: implemented `php.Lib.mail()`
 	php7: implemented `php.Lib.loadLib()`
 	php7: implemented `php.Lib.getClasses()` (#6384)
+	php7: fix exception on `Reflect.getProperty(o, field)` if requested field does not exist (#6559)
 	php/php7: fixed accessing enum constructors on enum type stored to a variable (#6159)
 	php/php7: fix "cannot implement previously implemented interface" (#6208)
 	php: fix invoking functions stored in dynamic static vars (#6158)

+ 1 - 0
std/php/_std/Reflect.hx

@@ -34,6 +34,7 @@
 	}
 
 	public static function getProperty( o : Dynamic, field : String ) : Dynamic {
+		#if php untyped __call__('var_dump', field); #end
 		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);

+ 7 - 0
std/php7/Boot.hx

@@ -271,6 +271,13 @@ class Boot {
 		return value;
 	}
 
+	/**
+		Unsafe cast to HxClass
+	**/
+	public static inline function castClass(cls:Class<Dynamic>) : HxClass {
+		return cast cls;
+	}
+
 	/**
 		Returns `Class<T>` for `HxClosure`
 	**/

+ 14 - 14
std/php7/_std/Reflect.hx

@@ -34,8 +34,8 @@ using php.Global;
 		if (o.property_exists(field)) return true;
 
 		if (Boot.isClass(o)) {
-			if (Global.property_exists(o.phpClassName, field)) return true;
-			return Global.method_exists(o.phpClassName, field);
+			var phpClassName = Boot.castClass(o).phpClassName;
+			return Global.property_exists(phpClassName, field) || Global.method_exists(phpClassName, field);
 		}
 
 		return false;
@@ -52,11 +52,12 @@ using php.Global;
 		}
 
 		if (Boot.isClass(o)) {
-			if (Global.property_exists(o.phpClassName, field)) {
+			var phpClassName = Boot.castClass(o).phpClassName;
+			if (Global.property_exists(phpClassName, field)) {
 				return Syntax.getField(o, field);
 			}
-			if (Global.method_exists(o.phpClassName, field)) {
-				return Boot.closure(o.phpClassName, field);
+			if (Global.method_exists(phpClassName, field)) {
+				return Boot.closure(phpClassName, field);
 			}
 		}
 
@@ -69,18 +70,17 @@ using php.Global;
 
 	public static function getProperty( o : Dynamic, field : String ) : Dynamic {
 		if (o.is_object()) {
-			if (Boot.hasGetter(Global.get_class(o), field)) {
+			if (Boot.isClass(o)) {
+				var phpClassName = Boot.castClass(o).phpClassName;
+				if (Boot.hasGetter(phpClassName, field)) {
+					return Syntax.staticCall(phpClassName, 'get_$field');
+				}
+			} else if (Boot.hasGetter(Global.get_class(o), field)) {
 				return Syntax.call(o, 'get_$field');
-			} else if (Global.method_exists(o, field)) {
-				return Boot.closure(o, field);
-			} else {
-				return Syntax.getField(o, field);
 			}
 		}
-		if (o.is_string() && field == 'length') {
-			return Global.strlen(o);
-		}
-		return null;
+
+		return Reflect.field(o, field);
 	}
 
 	public static function setProperty( o : Dynamic, field : String, value : Dynamic ) : Void {