Browse Source

[Php] generate field inits of properties (fixed issue #1087, fixed issue #1100)

Simon Krajewski 13 năm trước cách đây
mục cha
commit
9052c2cf1b
1 tập tin đã thay đổi với 10 bổ sung8 xóa
  1. 10 8
      genphp.ml

+ 10 - 8
genphp.ml

@@ -1805,6 +1805,13 @@ let generate_self_method ctx rights m static setter =
 	);
 	newline ctx
 
+let gen_assigned_value ctx eo =	match eo with
+	| Some ({eexpr = TConst _} as e) ->
+		print ctx " = ";
+		gen_value ctx e
+	| _ ->
+		()
+	
 let generate_field ctx static f =
 	newline ctx;
 	ctx.locals <- PMap.empty;
@@ -1851,10 +1858,12 @@ let generate_field ctx static f =
 				| AccCall m, _ ->
 					if not (is_method_defined ctx m static) then generate_self_method ctx rights m static false;
 					print ctx "%s $%s" rights (s_ident f.cf_name);
+					gen_assigned_value ctx f.cf_expr;
 					true
 				| _, AccCall m ->
 					if not (is_method_defined ctx m static) then generate_self_method ctx rights m static true;
 					print ctx "%s $%s" rights (s_ident f.cf_name);
+					gen_assigned_value ctx f.cf_expr;
 					true
 				| _ ->
 					false)
@@ -1877,14 +1886,7 @@ let generate_field ctx static f =
 					()
 				);
 			print ctx "%s $%s" rights name;
-			match f.cf_expr with
-			| None -> ()
-			| Some e ->
-				match e.eexpr with
-				| TConst _ ->
-					print ctx " = ";
-					gen_value ctx e
-				| _ -> ()
+			gen_assigned_value ctx f.cf_expr
 		end
 
 let generate_static_field_assign ctx path f =