Browse Source

- php: fixed issues with classes implementing Dynamic

Franco Ponticelli 16 years ago
parent
commit
254a5ff1fe
4 changed files with 17 additions and 3 deletions
  1. 1 0
      doc/CHANGES.txt
  2. 2 2
      genphp.ml
  3. 1 1
      std/Reflect.hx
  4. 13 0
      std/php/Boot.hx

+ 1 - 0
doc/CHANGES.txt

@@ -8,6 +8,7 @@
 	all : optimize constant equality for enums
 	all : optimize constant equality for enums
 	flash9 : fixed verify error with inline + null type
 	flash9 : fixed verify error with inline + null type
 	flash9 : bugfix when overriding/implementing an method with an applied type parameter
 	flash9 : bugfix when overriding/implementing an method with an applied type parameter
+	php: fixed issues with classes that implement Dynamic
 
 
 2009-07-26: 2.04
 2009-07-26: 2.04
 	flash9 : fixed get_full_path error with -D fdb
 	flash9 : fixed get_full_path error with -D fdb

+ 2 - 2
genphp.ml

@@ -1838,12 +1838,12 @@ let generate_class ctx c =
 	(match c.cl_dynamic with
 	(match c.cl_dynamic with
 		| Some _ when not c.cl_interface && not (super_has_dynamic c) ->
 		| Some _ when not c.cl_interface && not (super_has_dynamic c) ->
 			newline ctx;
 			newline ctx;
-			spr ctx "private $»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(is_callable($this->»dynamics[$n]))\n\t\t\treturn call_user_func_array($this->»dynamics[$n], $a);\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 _
 		| Some _
 		| _ ->
 		| _ ->
 			if List.length ctx.dynamic_methods > 0 then begin
 			if List.length ctx.dynamic_methods > 0 then begin
 				newline ctx;
 				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\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' == $n)\n\t\t\treturn $this->__toString();\n\t\telse\n\t\t\tthrow new HException('Unable to call «'.$m.'»');\n\t}";
 			end;
 			end;
 	);
 	);
 
 

+ 1 - 1
std/Reflect.hx

@@ -195,7 +195,7 @@ class Reflect {
 					? __php__("new _hx_array(array('concat','copy','insert','iterator','length','join','pop','push','remove','reverse','shift','slice','sort','splice','toString','unshift'))")
 					? __php__("new _hx_array(array('concat','copy','insert','iterator','length','join','pop','push','remove','reverse','shift','slice','sort','splice','toString','unshift'))")
 					: (__call__('is_string', o)
 					: (__call__('is_string', o)
 						? __php__("new _hx_array(array('charAt','charCodeAt','indexOf','lastIndexOf','length','split','substr','toLowerCase','toString','toUpperCase'))")
 						? __php__("new _hx_array(array('charAt','charCodeAt','indexOf','lastIndexOf','length','split','substr','toLowerCase','toString','toUpperCase'))")
-						: __php__("new _hx_array(array_keys(get_object_vars($o)))"));
+						: __php__("new _hx_array(_hx_get_object_vars($o))"));
 		#else
 		#else
 			return new Array();
 			return new Array();
 		#end
 		#end

+ 13 - 0
std/php/Boot.hx

@@ -313,6 +313,19 @@ 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));
+	$arr = array();
+	while($k = current($a)) {
+		if(substr($k, 0, 1) != '»')
+			$arr[] = $k;
+		next($a);
+	}
+	return $arr;
+}
+
 function _hx_has_field($o, $field) {
 function _hx_has_field($o, $field) {
 	return
 	return
 		(is_object($o) && (method_exists($o, $field) || isset($o->$field) || property_exists($o, $field)))
 		(is_object($o) && (method_exists($o, $field) || isset($o->$field) || property_exists($o, $field)))