Skip to content

Language: outside call to private method throws instead of __call (re-#146, zend_object_handlers.c) #25669

Description

@PurHur

Category

Language · php-src-strict · magic method visibility (regression vs #146)

Problem

Zend: calling a private method from a scope that cannot see it is treated as “method not found” for that scope, so __call runs. The VM raises Error: Call to private method … from global scope and never enters __call.

Repro (2026-07-31) Zend 8.2 VM
$a->hid() with private function hid() + __call CALL_hid / m Error: Call to private method A::hid() from global scope

php-src reference

PHP implementation target

  • lib/VM.php — method lookup / call frame setup (~__call dispatch ~16561+): when a method exists but visibility fails for the calling scope, fall through to __call with ($name, $arguments) (see existing MagicCallArgs) instead of throwing private-access Error
  • Do not add C runtime branches
  • Compliance: test/compliance/cases/language/magic_call_private.phpt

Repro

./script/docker-exec.sh -- bash -lc 'cat > /tmp/call_priv.php <<'"'"'PHP'"'"'
<?php
class A {
  private function hid() { return "p"; }
  public function __call($n, $a) { echo "CALL_$n\n"; return "m"; }
}
$a = new A();
echo $a->hid(), "\n";
PHP
php bin/vm.php /tmp/call_priv.php'

Done when

  • Outside-scope call to private/protected instance method invokes __call with Zend args packing
  • Same-class / allowed-scope calls still hit the real method (no __call)
  • Error message for truly missing methods unchanged
  • Compliance PHPT; php-src-strict

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 machinebugSomething isn't workingimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-2:languagePhase 2 – language features

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions