1

I have code where I use some variables. Example:

$name = "someName";
$output = sprintf($doingText, $name); // $doingText is here undefined

I want to search the code for surely undefined variables (some sort of static code analysing).

These variables should be all some language text. No problem until there, but I don't want to make manually a list which variables exist: I want to get the variable names and then make some html form where I can see them and put into database in variablename-text pairs.

Question is: how to search them? (I haven't found any script which is able to do this in PHP by googling...)

(p.s.: I don't know what is the best method to search them as there may not be only assignments by =, but also with foreach ($arr as $val) etc.)

bwoebi
  • 23,637
  • 5
  • 58
  • 79

1 Answers1

0

Why not use an IDE like NetBeans? That will actively check if you have unused variables. So while your coding it will show you in real time, rather then finish the script and find out you have x amount of errors/unused variables. Just food for thought.

Rixhers Ajazi
  • 1,303
  • 11
  • 18
  • I want to integrate this in some Control Panel... (p.s.: My IDE is also able to show me the undefined variables, but there are sometime false positives like "property of class null does not exist" — I want to do this via php ;)) – bwoebi Apr 06 '13 at 19:54
  • +1 a good IDE will warn you for unused and (possibly) undefined variables. You may also check [PhpStorm](http://www.jetbrains.com/phpstorm/) it has very many options for inspecting/validating your code – thaJeztah Apr 06 '13 at 19:54
  • 1
    I USE PhpStorm ;) But I want to do it directly via PHP? – bwoebi Apr 06 '13 at 19:55