Skip to content

Stdlib: ReflectionProperty::setRawValue()/getRawValue() — bypass hooks for init (PHP 8.4, ext/reflection/php_reflection.c) #6451

Description

@PurHur

Category

stdlib | language · php-src-strict (PHP 8.4)

Problem

PHP 8.4 adds ReflectionProperty::setRawValue(object $object, mixed $value) and getRawValue(object $object): mixed to read/write backing storage without invoking property hooks. Required for serializers, ORMs, and tests that initialize hooked properties before hooks are wired.

This compiler has property-hook VM dispatch (#4687, #6427) but no ReflectionProperty raw-value API — method_exists(ReflectionProperty::class, 'setRawValue') is false under bin/vm.php.

php-src reference

Repro (failure today)

Save as test/repro/maintainer_reflection_property_raw_value.php:

<?php
class Box {
    private string $label = 'init';
    public string $name {
        get => strtoupper($this->label);
        set => $this->label = strtolower($value);
    }
}

$o = new Box();
$rp = new ReflectionProperty(Box::class, 'name');

if (!method_exists($rp, 'setRawValue')) {
    echo "missing setRawValue\n";
    exit(1);
}

$rp->setRawValue($o, 'RAW');
echo $o->name, "\n";           // hook get => STRtoupper('RAW') => 'RAW' if backing updated
echo $rp->getRawValue($o), "\n"; // Zend: 'RAW' (backing field)
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php bin/vm.php test/repro/maintainer_reflection_property_raw_value.php 2>&1 | head -5
# missing setRawValue / exit 1
'
Step Zend PHP 8.4 VM today
method_exists(..., setRawValue) true false ❌
After setRawValue($o, 'RAW') getRawValue → 'RAW'; ->name uses get hook n/a

Scope (this repo)

Path Work
ext/reflection/ or lib/VM/BuiltinClasses.php Register setRawValue / getRawValue on ReflectionProperty
lib/VM/PropertyHookSupport.php Write/read backing slot without invoking hooks
Tests test/compliance/cases/stdlib/reflection_property_raw_value.phpt

PHP-in-PHP: reflection methods in PHP/VM; no new runtime/*.c.

Done when

  • method_exists(ReflectionProperty::class, 'setRawValue') true on VM
  • Repro: setRawValue updates backing; get() still runs get hook; getRawValue returns backing
  • Invalid targets (unhooked properties, static props) throw Zend-equivalent ReflectionException / TypeError
  • ./script/ci-fast.sh --filter reflection_property_raw green

Related: instance hooks #4687, static hooks #9520, #1492

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