PHPackages                             klitsche/clang-ffi - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. klitsche/clang-ffi

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

klitsche/clang-ffi
==================

libclang binding via ffi

v0.5.0(4y ago)024MITPHPPHP ^7.4 || ^8.0

Since Jan 1Pushed 4y ago1 watchersCompare

[ Source](https://github.com/klitsche/clang-ffi)[ Packagist](https://packagist.org/packages/klitsche/clang-ffi)[ Docs](https://github.com/klitsche/clang-ffi)[ RSS](/packages/klitsche-clang-ffi/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (5)Versions (6)Used By (0)

clang-ffi
=========

[](#clang-ffi)

[![Build](https://github.com/klitsche/clang-ffi/workflows/Build/badge.svg)](https://github.com/klitsche/clang-ffi/actions?query=workflow%3Atest)[![Build macOS](https://github.com/klitsche/clang-ffi/workflows/Build%20macOS/badge.svg)](https://github.com/klitsche/clang-ffi/actions?query=workflow%3Atest-macos)

[![Test Coverage](https://camo.githubusercontent.com/8b5f12570271a7536fb61e57930024bb1116493232c36d2126c1ed84c3ba3702/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f34333966366366343561646338356334363363632f746573745f636f766572616765)](https://codeclimate.com/github/klitsche/clang-ffi/test_coverage)[![Maintainability](https://camo.githubusercontent.com/5a2a3e81d6c077575b7c6f6cb4e4bf43071f66e3e05f0507827129b51ec6e7b2/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f34333966366366343561646338356334363363632f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/klitsche/clang-ffi/maintainability)[![Packagist](https://camo.githubusercontent.com/5e8f8fe4cea24a085d5813185dab6c34adbee4fc5010dab479ba8cd421115a61/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6b6c6974736368652f636c616e672d666669)](https://packagist.org/packages/klitsche/clang-ffi)

A library for PHP exposing libclang via FFI.

It allows easy traversing and analyzing of an abstract syntax tree of a c / c++ file.

Unfortunately PHP FFI does not currently support Struct By Value as parameter or return value in function calls. That is why a c based wrapper is provided for libclang itself, which can then be bound via FFI. This wrapper must be compiled before use.

The wrapper is taken from [dart ffigen](https://github.com/dart-lang/ffigen) and has been slightly extended.

Expect breaking changes along all 0.\* pre-releases.

Requirements
------------

[](#requirements)

- PHP &gt;= 7.4
- FFI extension enabled
- LLVM &gt;= 9 with clang and libclang-dev

Quick Start
-----------

[](#quick-start)

Install llvm with clang ...

... on macOS (see )

```
brew install llvm@11

```

... on Debian / Ubuntu (see )

```
apt-get update; \
apt-get install wget lsb-release software-properties-common ca-certificates gnupg; \
wget -q https://apt.llvm.org/llvm.sh; \
chmod +x llvm.sh; \
sudo ./llvm.sh 11; \
apt-get install libclang-11-dev;

```

Install in your project

```
composer require klitsche/clang-ffi

```

Add to composer.json (this will trigger compilation of wrapped libclang library)

```
"scripts": {
    "post-autoload-dump": "Klitsche\\Clang\\FFI\\libclang\\Compiler::run",
},
```

Dump autoload to trigger compilation

```
composer dump-autoload

```

Run examples
------------

[](#run-examples)

Checkout &amp; prepare

```
git clone https://github.com/klitsche/clang-ffi.git; \
cd clang-ffi; \
docker-compose build;

```

Print parsed file

```
docker-compose run --rm php74 php examples/print.php

```

Collect and dump simplified AST nodes as json

```
docker-compose run --rm php74 php examples/json.php

```

Dump found issues during parsing

```
docker-compose run --rm php74 php examples/issues.php

```

Todos
-----

[](#todos)

- Add ffigen
- Add multiversion support for llvm &gt;9 (some const values are different)
- Add documentation
- Add support for Windows

License
-------

[](#license)

See [LICENSE.md](LICENSE.md) for details.

[LICENSE.wrapper.c.md](LICENSE.wrapper.c.md) covers file src/FFI/libclang/wrapper.c.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~100 days

Total

5

Last Release

1558d ago

PHP version history (2 changes)v0.1.0PHP &gt;=7.4

v0.4.0PHP ^7.4 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/b53d403fce38ae29e4d8368820988c0e4c936193655d95dd7e06b533099a1bee?d=identicon)[dirx](/maintainers/dirx)

---

Top Contributors

[![dirx](https://avatars.githubusercontent.com/u/795259?v=4)](https://github.com/dirx "dirx (25 commits)")

---

Tags

clang-ffiffilibclangllvmphpphp-ffiwrapper

###  Code Quality

TestsPHPUnit

Code StyleECS

### Embed Badge

![Health badge](/badges/klitsche-clang-ffi/health.svg)

```
[![Health](https://phpackages.com/badges/klitsche-clang-ffi/health.svg)](https://phpackages.com/packages/klitsche-clang-ffi)
```

###  Alternatives

[friendsofphp/php-cs-fixer

A tool to automatically fix PHP code style

13.5k234.7M20.6k](/packages/friendsofphp-php-cs-fixer)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

728272.9k20](/packages/civicrm-civicrm-core)[shivas/versioning-bundle

Symfony application versioning, simple console command to manage version (with providers e.g. git tag) of your application using Semantic Versioning 2.0.0 recommendations

1121.2M1](/packages/shivas-versioning-bundle)[eclipxe/cfdiutils

PHP Common utilities for Mexican CFDI 3.2, 3.3 &amp; 4.0

141129.9k6](/packages/eclipxe-cfdiutils)[shyim/danger-php

Port of danger to PHP

8544.9k](/packages/shyim-danger-php)[vaimo/composer-changelogs

Provide information about package changes based on changelog files that are bundled with releases; provide tools for generating documentation files from changelog sources

11150.5k10](/packages/vaimo-composer-changelogs)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
