Sfoglia il codice sorgente

[php] Make possible to check for NativeArray with Std.is() (fixes #5565)

Alexander Kuzmenko 8 anni fa
parent
commit
c7e31f6f98
3 ha cambiato i file con 16 aggiunte e 2 eliminazioni
  1. 6 1
      std/php/Boot.hx
  2. 1 1
      std/php7/Boot.hx
  3. 9 0
      tests/unit/src/unit/issues/Issue5565.hx

+ 6 - 1
std/php/Boot.hx

@@ -451,6 +451,7 @@ function _hx_instanceof($v, $t) {
 		case 'Dynamic': return true;
 		case 'Class'  : return ($v instanceof _hx_class || $v instanceof _hx_interface) && $v->__tname__ != 'Enum';
 		case 'Enum'   : return $v instanceof _hx_enum;
+		case 'php.NativeArray': return is_array($v);
 		default       : return is_a($v, $t->__tname__);
 	}
 }
@@ -538,7 +539,11 @@ _hx_nullob::$inst = new _hx_nullob();
 function _hx_nullob() { return _hx_nullob::$inst; }
 
 function _hx_qtype($n) {
-	return isset(php_Boot::$qtypes[$n]) ? php_Boot::$qtypes[$n] : null;
+	if(!isset(php_Boot::$qtypes[$n])) {
+		php_Boot::$qtypes[$n] = new _hx_type($n, null);
+	}
+
+	return php_Boot::$qtypes[$n];
 }
 
 function _hx_register_type($t) {

+ 1 - 1
std/php7/Boot.hx

@@ -414,7 +414,7 @@ class Boot {
 				return value.is_bool();
 			case 'String':
 				return value.is_string();
-			case 'php\\NativeArray':
+			case 'php\\NativeArray', 'php\\_NativeArray\\NativeArray_Impl_':
 				return value.is_array();
 			case 'Enum', 'Class':
 				if (Syntax.instanceof(value, HxClass)) {

+ 9 - 0
tests/unit/src/unit/issues/Issue5565.hx

@@ -0,0 +1,9 @@
+package unit.issues;
+
+class Issue5565 extends Test {
+	function test() {
+		#if php
+        t(Std.is(untyped __php__('[]'), php.NativeArray));
+        #end
+	}
+}