Browse Source

- php: new fixes for classes that implement Dynamic

Franco Ponticelli 16 years ago
parent
commit
ccf8caf7c4
3 changed files with 5 additions and 3 deletions
  1. 1 1
      genphp.ml
  2. 1 1
      std/Reflect.hx
  3. 3 1
      std/php/Boot.hx

+ 1 - 1
genphp.ml

@@ -1843,7 +1843,7 @@ let generate_class ctx c =
 		| _ ->
 			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' == $n)\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;
 	);
 

+ 1 - 1
std/Reflect.hx

@@ -329,7 +329,7 @@ class Reflect {
 			return __dollar__objremove(o,__dollar__hash(f.__s));
 		#elseif php
 			if(!hasField(o,f)) return false;
-			untyped __php__("unset($o->$f)");
+			untyped __php__("if(isset($o->»dynamics[$f])) unset($o->»dynamics[$f]); else unset($o->$f)");
 			return true;
 		#else
 			return false;

+ 3 - 1
std/php/Boot.hx

@@ -303,6 +303,8 @@ function _hx_field($o, $field) {
 							return $o->$field;
 						}
 					}
+				} else if(isset($o->»dynamics[$field])) {
+					return $o->»dynamics[$field];
 				} else {
 					return array($o, $field);
 				}
@@ -328,7 +330,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)))
+		(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'))))
 	;