1

I am trying to find a static analysis tool that is able to output every object + method that my PHP application runs through. I am currently using xdebug, which does its work but is a runtime analysis tool. And ignores a lot of paths, because they are not run through.

I am trying to achieve something like this:

class C
{
    public function __construct() {
        $this->m1(true);
    }

    public function m1($p) {
        if ($p === true) {
            $this->m2();
        } else {
            $this->m3();
        }
    }

    private function m2() {
        // do stuff
    }

    private function m3() {
        // do other stuff
    }
}

Which would output something like this:

** rest of application **
  -> c->__construct()
    -> c->m1()
      -> c->m2()
      -> c->m3()
** rest of application **

Does anyone know of such a tool?

Stefan Schouten
  • 249
  • 4
  • 14
  • 1
    so you want the trace... http://php.net/manual/en/function.debug-backtrace.php – Barkermn01 Sep 07 '15 at 09:12
  • 1
    @MartinBarker: That wouldn't be a static analysis, but runtime analysis, which is best done using xdebug anyway ;) – Elias Van Ootegem Sep 07 '15 at 09:18
  • @MartinBarker as Elias says, this is runtime. I have edited my question to show what I mean; look at what m1 does now and what the output would be. – Stefan Schouten Sep 07 '15 at 09:18
  • you could use http://www.phpdoc.org/ however this would not provide exactly what your wanting but it should scan every file then if you comment correctly i think it can do it for you... other wise i don't think there is something as what your wanting would have to be build into a php parser E.G built in C++ code using the php source code. – Barkermn01 Sep 07 '15 at 09:22
  • 1
    @StefanSchouten: PHP doesn't tend to lend itself to static analysis (as its runtime is, well, messy, hard to predict and subject to change at runtime). There are some things that you can use, though [in the QA toolchain](http://phpqatools.org/). Basically, most decent profiling tools (blackfire.io, xhprof, VLD) do need your code to run. The only static analysis option that closely resembles PHP is to use [hack + hhvm](https://blog.engineyard.com/2014/hhvm-hack-part-5) – Elias Van Ootegem Sep 07 '15 at 09:23
  • here's a list of static analysis tools over [here][1]. [1]: http://stackoverflow.com/questions/378959/is-there-a-static-code-analyzer-like-lint-for-php-files – shivanshu patel Sep 07 '15 at 09:25
  • @MartinBarker: the problem is that this application uses over 1000 units as it is part of a larger application. I cannot add scanning documentation as that takes too much time. I have been thinking of building my own parser, but the amount of time I have for analysis does not allow me to do so :-) – Stefan Schouten Sep 07 '15 at 09:32
  • you could look at modifying something like https://github.com/psecio/parse or any php parser. – Barkermn01 Sep 07 '15 at 09:35
  • @EliasVanOotegem: The tools in the Toolchain do not remotely offer me what I want: tracing of every possible path. I am okay with running the code if that means that it could find every possible path. Blackfire.io seems interesting; I'll take a look at how it works. – Stefan Schouten Sep 07 '15 at 09:39
  • @StefanSchouten: I know the QA toolchain doesn't offer the kind of analysis you're after, but it's a starting point. My point was mainly that you'll have to use runtime analysis to get the full picture. Another good starting point, BTW is [PHPCallGraph](http://phpcallgraph.sourceforge.net/), though I don't know if it's still being maintained – Elias Van Ootegem Sep 07 '15 at 09:42
  • @EliasVanOotegem: Thanks for your input, though: blackfire.io does not seem to do what I want and PHPCallGraph does not work correctly as it is indeed outdated and not working correctly anymore. I seem to find that what I want is either impossible or not wanted enough. I think I found mysel a spare time project :-) – Stefan Schouten Sep 07 '15 at 10:21
  • 2
    @StefanSchouten: I'm afraid that what you're after is very much wanted (most serious PHP devs would love some static analysis tool), but it's just not possible: PHP's extension architecture and request cycle is a black-box to any third party tool (what goes on at RSHUTDOWN and RINIT is not known), the runtime can change during runtime (error handling, `ini_set` calls), depending on what is in the `$_REQUEST` (a runtime var) variable... tl;tr: runtime analysis is possible, static is not – Elias Van Ootegem Sep 07 '15 at 10:23

0 Answers0