Created: 2008-12-03 23:44
Updated: 2019-01-25 05:26
License: mit



Build Status Codacy Badge Maintainability BCH compliance Coverage Status

phpweaver is a tool for analysing parameter types in PHP code, using a combination of static and runtime analysis. It relies on the xdebug extension to trace function calls. The result of the analysis can then be used to generate docblock comments, with the proper type annotations.


The basic usage of phpweaver is to write a piece of code (If you have unit tests/examples, they would be a good candidate), that utilises the code to manipulate. Run this example with the tracer, then use weaver to generate docblocks from the trace.

See the example/ folder for a basic example.

The project has two main commands:

  • trace
  • weave


This is just a wrapper around php + xdebug. Use it in lieu of php to execute a php script. It will run normally, but the code is traced and the output is dumped in dumpfile.xt. You can also manually configure xdebug to generate the tracefile.

Sample usage:

phpweaver trace test.php

If your script requires it's own paremeter you can stop paramerter pasing in bash with the duble dash:

phpweaver trace -- vendor/bin/phpunit "-c phpunit.xml"


This command takes a dumpfile (Generated by the trace process) and a php-source path (directory or file), and injects docblock comments into the php-source, using the type-information from the trace. It will look for dumpfile.xt in the current directory, or a trace file specifyed using the --tracefile option, printing the modified file to stdout.

Sample usage:

phpweaver weave somelibrary.php

The same dumpfile can be used to weave multiple files, by specifying a folder or multiple paths.

Running tests

There is a Dockerfile for getting an environment up and running. First install docker somehow, then issue:

docker build -t phpweaver .
docker run -it phpweaver

This will log you in to the machine. Run tests with:


For development, you will probably want to mount the repo into the container, so run it like this:

docker run -it --mount type=bind,source="$(pwd)",target=/usr/src/app phpweaver

Any changes you make inside the container will now be reflected on your host system.

Cookies help us deliver our services. By using our services, you agree to our use of cookies Learn more