Skip to content

Language: ReflectionClass::getMethods() exposes parent private methods on child class (ext/reflection/php_reflection.c, php-src-strict) #7191

Description

@PurHur

Category

language | stdlib

Problem

ReflectionClass::getMethods() on a child class must not include private methods declared on the parent (php-src filters by declaring-class visibility rules). This compiler lists them today, breaking PHPUnit filters, DI scanners, and serialization metadata that rely on Zend-accurate method sets.

Umbrella/filter flags: #4480. This issue is the inheritance private-leak repro only — implement here or as first slice of #4480.

php-src reference

Repro (failure today — verified 2026-06-07)

<?php
declare(strict_types=1);

class A {
    public function pubA(): void {}
    protected function protA(): void {}
    private function privA(): void {}
    public static function statA(): void {}
}
class B extends A {
    public function pubB(): void {}
    private function privB(): void {}
}

$r = new ReflectionClass(B::class);
$names = array_map(fn ($m) => $m->getName(), $r->getMethods());
sort($names);
var_export($names);
echo "\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php repro_reflection_getmethods_private.php > /tmp/zend.txt
php bin/vm.php repro_reflection_getmethods_private.php > /tmp/vm.txt
diff -u /tmp/zend.txt /tmp/vm.txt
'
Runtime $names includes privA?
Zend PHP 8.x no (parent private hidden on child)
bin/vm.php yes — ['privA','privB','protA','pubA','pubB','statA'] observed

Scope (this repo)

Layer Path
VM reflection ext/standard/VmReflection.php — skip parent-private entries when $ce !== declaring class
Class tables lib/VM/ClassEntry.php method metadata (declaring class + visibility)
Tests test/compliance/cases/stdlib/reflection_class_getmethods_private.phpt

PHP-in-PHP: walk CE tables in PHP; no new C reflection shims (#5301).

Done when

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter reflection_class_getmethods_private'

Links

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:vmVirtual machineenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-2:languagePhase 2 – language featuresphase-4:stdlibPhase 4 – stdlib for web apps

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions