Extracts list of dependencies (classes, interfaces & traits) from PHP file or code snippet.

Fund package maintenance!

v2.0.0 2023-03-31 08:58 UTC

This package is auto-updated.

Last update: 2024-06-30 00:52:15 UTC



Build Status Downloads this Month Latest Stable Version License

Extracts list of dependencies (classes, interfaces & traits) from PHP file or code snippet.



Download a latest package or use Composer:

composer require czproject/phpdepend

PhpDepend requires PHP 5.6 or later and enabled Tokenizer extension (enabled by default from PHP 4.3.0).


$phpdepend = new CzProject\PhpDepend\PhpDepend;

// file parsing

// code snippet parsing
$source = file_get_contents('MyClass.php');

// getting result
$phpdepend->getClasses(); // returns list of defined classes, interfaces & traits
$phpdepend->getDependencies(); // returns list of required classes, interfaces & traits

Recognized dependencies in PHP code:

  • inherited classes (extends ParentClass)
  • implemented interfaces (implements InterfaceA, InterfaceB)
  • used traits (class MyClass { use Trait; })
  • classes of created instances (new Object())
  • static classes (StaticClass::staticMethod(), StaticClass::$staticProperty)

Ignored dependencies:

  • self:: - self means "this class" → useless (no dependency, class is defined in same file)
  • parent:: - parent class is specified in extends
  • static:: - static is dynamic-self → means "this class", parent or descendant (if exists)

Recognized defined classes (output of $phpdepend->getClasses()):

  • defined classes (class MyClass)
  • defined interfaces (interface MyInterface)
  • defined traits (trait MyTrait)


$phpdepend = new CzProject\PhpDepend\PhpDepend;
	class Greeting implements IGreeting
		public function say($name)
			if (!$name) {
				throw new InvalidArgumentException("Invalid name");
			return "Hello $name";

	$greeting = new Greeting;

/* Output:
array (1) {

/* Output:
array (3) {

License: New BSD License
Author: Jan Pecha,