Skip to content

Fatal Error: Cannot modify readonly property Yiisoft\Yii\Http\Application::$dispatcher in HttpApplicationWrapper #160

Description

@konapaz

Description

Description:
When trying to use yiisoft/yii-debug-api with the latest versions of Yii3 core packages (specifically where Yiisoft\Yii\Http\Application::$dispatcher has been refactored to be a readonly property), a Fatal Error is thrown on every request.

The wrapper attempts to modify this readonly property via reflection/closure, which PHP explicitly forbids, crashing the entire application.

Error Stack Trace:

Unhandled error "Cannot modify readonly property Yiisoft\Yii\Http\Application::$dispatcher" while building "Yiisoft\Yii\Http\Application".

Caused by: Error
Cannot modify readonly property Yiisoft\Yii\Http\Application::$dispatcher
in ./vendor/yiisoft/yii-debug-api/src/Debug/Http/HttpApplicationWrapper.php at line 29

Steps to Reproduce:

  • Install yiisoft/yii-debug:dev-master and yiisoft/yii-debug-api:dev-master with Symfony 6.4+/7.x support.
  • Enable the debug extension in config/params.php.
  • Try to access any endpoint or the /debug route.

Environment:
PHP Version: 8.2.12
Framework: Yii3 (latest dev-master / stable components)
Package Version: yiisoft/yii-debug-api (dev-master / 3.0.x-dev)

Proposed Solution:
The HttpApplicationWrapper.php needs to be refactored so it doesn't attempt to overwrite the $dispatcher property directly if it is marked as readonly, or Yii3's Application class should provide a safe way to intercept or decorate the dispatcher without mutating a readonly state.

Package version

yiisoft/yii-debug-api: 3.0.x-dev (dev-master) | yiisoft/yii-debug: 3.0.x-dev (dev-master)

PHP version

8.2.12

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions