瀏覽代碼

Fixed exception thrown by `Reflect.fields(o)` when `o` is `Class<T>` (fixes #5608) (#5884)

* [php] test case for #5608

* [php7] do not throw on Reflect.fields(o) when o is a Class (fixes #5608)
Alexander Kuzmenko 8 年之前
父節點
當前提交
2fc83d6b0a
共有 4 個文件被更改,包括 21 次插入6 次删除
  1. 2 0
      extra/CHANGES.txt
  2. 0 2
      src/generators/genphp.ml
  3. 8 4
      std/php/Boot.hx
  4. 11 0
      tests/unit/src/unit/issues/Issue5608.hx

+ 2 - 0
extra/CHANGES.txt

@@ -23,6 +23,8 @@
 	php : fixed invalid detection of `NativeArray` by `Std.is()` (#5565)
 	php : fixed `stdin()`, `stdout()`, `stderr()` of `Sys` to use predefined constants for corresponding channels (#5733)
 	php : fixed Std.parseInt() on hexstrings for PHP7+ (#5521)
+	php : fixed typed cast in assign operations (#5135)
+	php : fixed exception thrown by `Reflect.fields(o)` when `o` is `Class<T>` (#5608)
 	php : fixed json encoding of empty objects (#5015)
 
 2016-11-29: 3.4.0-RC1

+ 0 - 2
src/generators/genphp.ml

@@ -1670,8 +1670,6 @@ and gen_expr ctx e =
 	| TCast (e,None) ->
 		gen_expr ctx e
 	| TCast (e1,Some t) ->
-		let error_message pos message = (Lexer.get_error_pos (Printf.sprintf "%s:%d:") pos) ^ ": " ^ message in
-		print_endline (error_message e1.epos "!!!TYPED CAST!!!");
 		let mk_texpr = function
 			| TClassDecl c -> TAnon { a_fields = PMap.empty; a_status = ref (Statics c) }
 			| TEnumDecl e -> TAnon { a_fields = PMap.empty; a_status = ref (EnumStatics e) }

+ 8 - 4
std/php/Boot.hx

@@ -793,9 +793,13 @@ class _hx_type {
 
 	public function __get($n) {
 		if(($r = $this->__rfl__())==null) return null;
-		if($r->hasProperty($n))
-			return $r->getStaticPropertyValue($n);
-		else if($r->hasMethod($n))
+		if($r->hasProperty($n)) {
+			try {
+				return $r->getStaticPropertyValue($n);
+			} catch(Exception $e) {
+				return null;
+			}
+		} else if($r->hasMethod($n))
 			return array($r->name, $n);
 		else
 			return null;
@@ -808,7 +812,7 @@ class _hx_type {
 
 	public function __isset($n) {
 		if(($r = $this->__rfl__())==null) return null;
-		return $r->hasProperty($n) || $r->hasMethod($n);
+		return array_key_exists($n, $r->getStaticProperties()) || $r->hasMethod($n);
 	}
 }
 

+ 11 - 0
tests/unit/src/unit/issues/Issue5608.hx

@@ -0,0 +1,11 @@
+package unit.issues;
+
+class Issue5608 extends unit.Test {
+	var fields:Array<String>;
+
+	function test() {
+		//should not throw
+		fields = Reflect.fields(haxe.remoting.HttpConnection);
+		t(true);
+	}
+}