Skip to content
Browse files

* lang_php/analyze/checker/check_variables_php.ml: first

  • Loading branch information...
1 parent 9bb2921 commit 812f5562cbf4bc53fcbabe5d15a81c23661103b1 @aryx aryx committed Aug 7, 2012
View
32 lang_php/analyze/checker/check_variables_php.ml
@@ -219,6 +219,20 @@ let s_tok_of_name name =
A.str_of_name name, A.tok_of_name name
(*****************************************************************************)
+(* Vars passed by ref *)
+(*****************************************************************************)
+(*
+ * Detecting variables passed by reference is complicated in PHP because
+ * one does not have to use &$var at the call site ... This is ugly ...
+ * So to detect variables passed by reference, we need to look at
+ * the definition of the function or method called, hence the
+ * find_entity argument
+ *)
+
+let funcdef_of_call_or_new_opt entity_finder_opt e =
+ None
+
+(*****************************************************************************)
(* Checks *)
(*****************************************************************************)
@@ -518,17 +532,27 @@ and expr env = function
(* todo: args passed by ref false positives fix *)
| Call (e, es) ->
expr env e;
- es +> List.iter (fun e ->
- match e with
+
+ let def_opt = funcdef_of_call_or_new_opt env.db (Call (e, es)) in
+ let es_with_parameters =
+ match def_opt with
+ | None ->
+ es +> List.map (fun e -> e, None)
+ | Some def ->
+ Common.zip_safe es (List.map (fun p -> Some p) def.f_params)
+ in
+
+ es_with_parameters +> List.iter (fun (arg, param_opt) ->
+ match arg, param_opt with
(* keyword argument; do not consider this variable as unused.
* We consider this variable as a pure comment here and just pass over.
* todo: could make sure they are not defined in the current
* environment in strict mode? and if they are, shout because of
* bad practice?
*)
- | Assign (None, Id name, e2) ->
+ | Assign (None, Id name, e2), _ ->
expr env e2
- | _ -> expr env e
+ | _ -> expr env arg
);
(* facebook specific? should be a hook instead to visit_prog? *)
View
2 lang_php/analyze/checker/unit_checker_php.ml
@@ -24,7 +24,7 @@ let unittest =
p "tests/php/scheck/common.php";
p "tests/php/scheck/includes.php";
p "tests/php/scheck/variables.php";
-(* TODO p "tests/php/scheck/variables_fp.php"; *)
+ p "tests/php/scheck/variables_fp.php";
p "tests/php/scheck/arrays.php";
p "tests/php/scheck/functions.php";
p "tests/php/scheck/static_methods.php";
View
9 lang_php/old/scheck/check_variables_helpers_php.ml
@@ -18,16 +18,7 @@ let vars_assigned_in_any any =
);
})
-(*****************************************************************************)
-(* Vars passed by ref *)
-(*****************************************************************************)
(*
- * Detecting variables passed by reference is complicated in PHP because
- * one does not have to use &$var at the call site ... This is ugly ...
- * So to detect variables passed by reference, we need to look at
- * the definition of the function or method called, hence the
- * find_entity argument.
- *
* less: maybe could be merged with vars_assigned_in but maybe we want
* the caller to differentiate between regular assignements
* and possibly assigned by being passed by ref

0 comments on commit 812f556

Please sign in to comment.
Something went wrong with that request. Please try again.