Skip to content

Language: private(set) Error::getLine() is caller — Zend assignment line in method (zend_object_handlers.c) #29665

Description

@PurHur

Category

Language · php-src-strict · asymmetric visibility · pillar 4

Problem

When a subclass method assigns to an inherited private(set) property, Zend throws Error: Cannot modify private(set) property A::$x from scope B with Error::getLine() = the assignment line inside the method. VM reports the call site line instead.

Message text matches; only the attributed source line (and thus stack top) diverges.

Probed 2026-08-10 vs php:8.4-cli with PHP_COMPILER_PROFILE=8.4.

Repro Zend 8.4 getLine() VM getLine()
B::setX does $this->x = $v; then $b->setX('z') line of $this->x = $v (inside setX) line of $b->setX('z') (caller)

php-src reference

PHP implementation target

  • lib/VM/ / lib/JIT/ property write path for private(set) / protected(set) — throw with the assign opcode location (method body), not the call opcode
  • No new C runtime

Repro

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
cat > /tmp/private_set_line.php << "PHP"
<?php
class A { public private(set) string $x = "a"; }
class B extends A {
  public function setX(string $v): void { $this->x = $v; }
}
$b = new B();
try { $b->setX("z"); } catch (Error \$e) {
  echo \$e->getMessage(), "\nline=", \$e->getLine(), "\n";
}
PHP
PHP_COMPILER_PROFILE=8.4 php bin/vm.php /tmp/private_set_line.php
# Zend: line=4 (assignment). VM today: line=7 (call).
'

Done when

  • Error::getLine() for forbidden private(set) write matches Zend (assignment in method), VM+JIT
  • Direct $b->x = … from outside still errors with correct external line
  • Compliance .phpt under test/compliance/cases/
  • php-src-strict; no php-compiler-strict shortcut

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:compilerCompiler / CFG / JITbugSomething 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