Skip to content

Language: #[AllowDynamicProperties] on parameter must compile-time fatal (zend_attributes.c) #5137

Description

@PurHur

Category

language | php-src-strict

Problem

#[AllowDynamicProperties] is only valid on classes in PHP 8.2+. Zend rejects it on parameters with a compile-time fatal. This compiler accepts the attribute on a parameter (with spurious CFG deprecation noise) instead of failing like php-src.

Related umbrella: #4392 (attributes), #5124 (#[\DelayedTargetValidation]). This issue is the specific AllowDynamicProperties disallowed target slice — not promoted-parameter delayed validation (valid in PHP 8.4 via #5124).

php-src reference

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

<?php
function f(#[AllowDynamicProperties] int $x) {}
echo "compiled\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php -r "function f(#[AllowDynamicProperties] int \$x) {} echo \"compiled\";" 2>&1 | head -1
php bin/vm.php -r "function f(#[AllowDynamicProperties] int \$x) {} echo \"compiled\";" 2>&1
'
Runtime Result
Zend PHP 8.2 Fatal error: Attribute "AllowDynamicProperties" cannot target parameter (allowed targets: class)
bin/vm.php prints compiled (compile succeeds)

Additional invalid targets (same fix)

Snippet Zend
#[AllowDynamicProperties] function g() {} cannot target function
class C { #[AllowDynamicProperties] public int $p; } cannot target property
const X = 1; #[AllowDynamicProperties] /* on const */ cannot target class constant

Add at least parameter + function cases to compliance PHPT.

Scope (this repo)

Layer Path
Early guard lib/Compiler/AttributeNames.php — assertAllowDynamicPropertiesClassTargetOnly() already called for some decls; extend to parameters and functions
Compile hook lib/Compiler.php — parameter/method/function attribute validation passes (~lines calling AttributeNames::assertAllowDynamicPropertiesClassTargetOnly)
Builtin class ext/standard/BuiltinAttributes.php — AllowDynamicProperties registered with TARGET_CLASS only (#7145)
JIT/AOT Compile-time only — invalid targets must fail before codegen (no runtime fallback)
Tests test/compliance/cases/language/allow_dynamic_properties_param_target.phpt

Do not add C runtime checks — reject in PHP compile path.

Done when

  • VM compile of parameter repro fails before runtime with message equivalent to Zend (cannot target parameter, allowed targets: class)
  • No successful echo "compiled" on VM for parameter repro
  • Function-target repro also fails at compile time
  • ./script/ci-fast.sh --filter allow_dynamic_properties_param green
  • No unrelated deprecation noise on the repro file when compile fails

Verification

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

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:compilerCompiler / CFG / JITarea:vmVirtual machineenhancementNew feature or requestimplementation-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