Docs / languages / php · Edit on GitHub

PHP

Tier 1 plugin for PHP source. Covers namespaces, use imports, classes, traits, static calls, and cross-file resolution.

Implementation

Plugin cratecrates/rgctl-lang-php (PhpPlugin)
Grammartree-sitter-php
Extensions.php
Discoverrgctl discover . -l php -e vendor,generated --with-cfg --with-taint
CFG / taintEnabled (taint on fixture discover)

Tree-sitter node kinds: function_definition, method_declaration, arrow_function, anonymous_function, class_declaration, interface_declaration, trait_declaration, namespace_use_declaration.

What is extracted

Nodes

  • Function, Class, Interface, Trait
  • Importuse statements (including aliases)

Edges

EdgeMeaning
CALLSFunction, method, and static calls
ImportNamespace import graph
USESTrait composition (openspec probe — may not emit yet)
ANNOTATEDWITHAttributes (openspec probe)
INSTANTIATESnew / anonymous class (openspec probe)

Cross-file static call resolution is verified (SampleService.runAuthService.login).

Verification

Fixturergctl-tests/ecommerce-php
Example corpusexample/magento2 (app lib setup -l php -e vendor -e generated)
Smoke scriptrgctl-tests/gql-verification-smoke/verify-extraction-gql-php.sh

GQL verification queries

Fixture probes

ProbeGQLNotes
Namespace imports (Import)MATCH (n:Import) RETURN n LIMIT 10000
Import by name (AuthService)MATCH (n:Import) WHERE n.name = 'AuthService' RETURN n
Aliased import (Order)MATCH (n:Import) WHERE n.name = 'Order' RETURN n
Call resolution (CALLS)MATCH (a)-[:CALLS]->(b) RETURN a,b LIMIT 10000
Cross-file static callMATCH (a:Function)-[:CALLS]->(b:Function) WHERE a.name = 'run' AND b.name = 'login' RETURN a,b
Namespace FQN on ClassMATCH (n:Class) WHERE n.name = 'AuthService' RETURN n
Method FQN (AuthService.login)MATCH (n:Function) WHERE n.name = 'login' RETURN n
Trait composition (USES)MATCH (a)-[:USES]->(b) RETURN a,b LIMIT 10000Soft probe
Attributes (ANNOTATEDWITH)MATCH (a)-[:ANNOTATEDWITH]->(b) RETURN a,b LIMIT 10000Soft probe
Anonymous class / new (INSTANTIATES)MATCH (a)-[:INSTANTIATES]->(b) RETURN a,b LIMIT 10000Soft probe

Example smoke (example/magento2)

ProbeGQL
Import (scale)MATCH (n:Import) RETURN n LIMIT 10000
CALLS (scale)MATCH (a)-[:CALLS]->(b) RETURN a,b LIMIT 10000

Related

  • Languages index
  • Openspec: php-trait-and-imports, php-framework-symbols, php-analysis-polish