Forráskód Böngészése

php: fixed Type specifications

Franco Ponticelli 12 éve
szülő
commit
1794f726b6
4 módosított fájl, 21 hozzáadás és 16 törlés
  1. 2 2
      genphp.ml
  2. 5 5
      std/php/Boot.hx
  3. 1 1
      std/php/_std/Reflect.hx
  4. 13 8
      std/php/_std/Type.hx

+ 2 - 2
genphp.ml

@@ -2071,12 +2071,12 @@ let generate_class ctx c =
 	(match c.cl_dynamic with
 		| Some _ when not c.cl_interface && not (super_has_dynamic c) ->
 			newline ctx;
-			spr ctx "public $»dynamics = array();\n\tpublic function __get($n) {\n\t\tif(isset($this->»dynamics[$n]))\n\t\t\treturn $this->»dynamics[$n];\n\t}\n\tpublic function __set($n, $v) {\n\t\t$this->»dynamics[$n] = $v;\n\t}\n\tpublic function __call($n, $a) {\n\t\tif(isset($this->»dynamics[$n]) && is_callable($this->»dynamics[$n]))\n\t\t\treturn call_user_func_array($this->»dynamics[$n], $a);\n\t\tif('toString' == $n)\n\t\t\treturn $this->__toString();\n\t\tthrow new HException(\"Unable to call «\".$n.\"»\");\n\t}"
+			spr ctx "public $__dynamics = array();\n\tpublic function __get($n) {\n\t\tif(isset($this->__dynamics[$n]))\n\t\t\treturn $this->__dynamics[$n];\n\t}\n\tpublic function __set($n, $v) {\n\t\t$this->__dynamics[$n] = $v;\n\t}\n\tpublic function __call($n, $a) {\n\t\tif(isset($this->__dynamics[$n]) && is_callable($this->__dynamics[$n]))\n\t\t\treturn call_user_func_array($this->__dynamics[$n], $a);\n\t\tif('toString' == $n)\n\t\t\treturn $this->__toString();\n\t\tthrow new HException(\"Unable to call «\".$n.\"»\");\n\t}"
 		| Some _
 		| _ ->
 			if List.length ctx.dynamic_methods > 0 then begin
 				newline ctx;
-				spr ctx "public function __call($m, $a) {\n\t\tif(isset($this->$m) && is_callable($this->$m))\n\t\t\treturn call_user_func_array($this->$m, $a);\n\t\telse if(isset($this->»dynamics[$m]) && is_callable($this->»dynamics[$m]))\n\t\t\treturn call_user_func_array($this->»dynamics[$m], $a);\n\t\telse if('toString' == $m)\n\t\t\treturn $this->__toString();\n\t\telse\n\t\t\tthrow new HException('Unable to call «'.$m.'»');\n\t}";
+				spr ctx "public function __call($m, $a) {\n\t\tif(isset($this->$m) && is_callable($this->$m))\n\t\t\treturn call_user_func_array($this->$m, $a);\n\t\telse if(isset($this->__dynamics[$m]) && is_callable($this->__dynamics[$m]))\n\t\t\treturn call_user_func_array($this->__dynamics[$m], $a);\n\t\telse if('toString' == $m)\n\t\t\treturn $this->__toString();\n\t\telse\n\t\t\tthrow new HException('Unable to call «'.$m.'»');\n\t}";
 			end;
 	);
 

+ 5 - 5
std/php/Boot.hx

@@ -363,8 +363,8 @@ function _hx_field($o, $field) {
 							return $o->$field;
 						}
 					}
-				} else if(isset($o->»dynamics[$field])) {
-					return $o->»dynamics[$field];
+				} else if(isset($o->__dynamics[$field])) {
+					return $o->__dynamics[$field];
 				} else {
 					return array($o, $field);
 				}
@@ -377,8 +377,8 @@ function _hx_field($o, $field) {
 
 function _hx_get_object_vars($o) {
 	$a = array_keys(get_object_vars($o));
-	if(isset($o->»dynamics))
-		$a = array_merge($a, array_keys($o->»dynamics));
+	if(isset($o->__dynamics))
+		$a = array_merge($a, array_keys($o->__dynamics));
 	$arr = array();
 	for($i=0;$i<count($a); $i++)
 	{
@@ -391,7 +391,7 @@ function _hx_get_object_vars($o) {
 
 function _hx_has_field($o, $field) {
 	return
-		(is_object($o) && (method_exists($o, $field) || isset($o->$field) || property_exists($o, $field) || isset($o->»dynamics[$field])))
+		(is_object($o) && (method_exists($o, $field) || isset($o->$field) || property_exists($o, $field) || isset($o->__dynamics[$field])))
 		||
 		(is_string($o) && (in_array($field, array('toUpperCase', 'toLowerCase', 'charAt', 'charCodeAt', 'indexOf', 'lastIndexOf', 'split', 'substr', 'toString', 'length'))))
 	;

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

@@ -95,7 +95,7 @@
 
 	public static function deleteField( o : Dynamic, f : String ) : Bool {
 		if(!hasField(o,f)) return false;
-		untyped __php__("if(isset($o->»dynamics[$f])) unset($o->»dynamics[$f]); else if($o instanceof _hx_anonymous) unset($o->$f); else $o->$f = null");
+		untyped __php__("if(isset($o->__dynamics[$f])) unset($o->__dynamics[$f]); else if($o instanceof _hx_anonymous) unset($o->$f); else $o->$f = null");
 		return true;
 	}
 

+ 13 - 8
std/php/_std/Type.hx

@@ -156,11 +156,12 @@ enum ValueType {
 		$ms = $rfl->getMethods();
 		while(list(, $m) = each($ms)) {
 			$n = $m->getName();
-			if(!$m->isStatic() && ! in_array($n, $internals)) $r[] = $n;
+			if(!$m->isStatic() && !in_array($n, $internals)) $r[] = $n;
 		}
 		$ps = $rfl->getProperties();
 		while(list(, $p) = each($ps))
-			if(!$p->isStatic()) $r[] = $p->getName()");
+			if(!$p->isStatic() && ($name = $p->getName()) !== '__dynamics') $r[] = $name;
+		");
 		return untyped __php__("new _hx_array(array_values(array_unique($r)))");
 	}
 
@@ -170,13 +171,17 @@ enum ValueType {
 		untyped __php__("
 		$rfl = $c->__rfl__();
 		if($rfl === null) return new _hx_array(array());
-		$ms = $rfl->getMethods();
+		$ms = $rfl->getMethods(ReflectionMethod::IS_STATIC);
 		$r = array();
-		while(list(, $m) = each($ms))
-			if($m->isStatic()) $r[] = $m->getName();
-		$ps = $rfl->getProperties();
-		while(list(, $p) = each($ps))
-			if($p->isStatic() && ($name = $p->getName()) !== '__properties__') $r[] = $name;
+		while(list(, $m) = each($ms)) {
+			$cls = $m->getDeclaringClass();
+			if($cls->getName() == $c->__tname__) $r[] = $m->getName();
+		}
+		$ps = $rfl->getProperties(ReflectionMethod::IS_STATIC);
+		while(list(, $p) = each($ps)) {
+			$cls = $p->getDeclaringClass();
+			if($cls->getName() == $c->__tname__ && ($name = $p->getName()) !== '__properties__') $r[] = $name;
+		}
 		");
 		return untyped __php__("new _hx_array(array_unique($r))");
 	}