Sfoglia il codice sorgente

[php] fixed accessing `static inline var` via reflection (fixes #6630)

Alexander Kuzmenko 8 anni fa
parent
commit
11f539b037

+ 1 - 0
extra/CHANGES.txt

@@ -2,6 +2,7 @@
 
 	Bugfixes:
 
+	php7 : fixed accessing `static inline var` via reflection (#6630)
 	js : fixed js syntax error for `value.iterator--` (#6637)
 
 2017-09-10: 3.4.3

+ 3 - 1
std/php7/Boot.hx

@@ -564,7 +564,9 @@ private class HxClass {
 	**/
 	@:phpMagic
 	function __get( property:String ) : Dynamic {
-		if (Boot.hasGetter(phpClassName, property)) {
+		if (Global.defined('$phpClassName::$property')) {
+			return Global.constant('$phpClassName::$property');
+		} else if (Boot.hasGetter(phpClassName, property)) {
 			return Syntax.staticCall(phpClassName, 'get_$property');
 		} else {
 			return Syntax.getStaticField(phpClassName, property);

+ 5 - 0
std/php7/Global.hx

@@ -275,6 +275,11 @@ extern class Global {
 	**/
 	static function defined( name:String ) : Bool;
 
+	/**
+		@see http://php.net/manual/en/function.constant.php
+	*/
+	static function constant( name:String ) : Dynamic;
+
 	/**
 		@see http://php.net/manual/en/function.define.php
 	**/

+ 4 - 1
std/php7/_std/Reflect.hx

@@ -35,7 +35,7 @@ using php.Global;
 
 		if (Boot.isClass(o)) {
 			var phpClassName = Boot.castClass(o).phpClassName;
-			return Global.property_exists(phpClassName, field) || Global.method_exists(phpClassName, field);
+			return Global.property_exists(phpClassName, field) || Global.method_exists(phpClassName, field) || Global.defined('$phpClassName::$field');
 		}
 
 		return false;
@@ -53,6 +53,9 @@ using php.Global;
 
 		if (Boot.isClass(o)) {
 			var phpClassName = Boot.castClass(o).phpClassName;
+			if (Global.defined('$phpClassName::$field')) {
+				return Global.constant('$phpClassName::$field');
+			}
 			if (Global.property_exists(phpClassName, field)) {
 				return Syntax.getField(o, field);
 			}

+ 13 - 0
tests/unit/src/unit/issues/Issue6630.hx

@@ -0,0 +1,13 @@
+package unit.issues;
+
+class Issue6630 extends unit.Test {
+	static var cls:Dynamic;
+	static inline var HELLO = 'hello';
+
+	function test() {
+		cls = Issue6630;
+		eq(cls.HELLO, HELLO);
+		eq(Reflect.field(Issue6630, 'HELLO'), HELLO);
+		t(Reflect.hasField(Issue6630, 'HELLO'));
+	}
+}