Skip to content

Conversation

@nanasess
Copy link
Contributor

@nanasess nanasess commented Oct 3, 2025

概要

AbstractMasterEntityのenum風プロパティアクセス機能を非推奨化します。

背景

PR #2437 で実装されたenum風プロパティアクセス機構について、以下の理由から非推奨とします:

  1. PHP 8.2以降の言語機能

    • PHP 8.2よりtraitでクラス定数を直接定義可能になった
    • マジックメソッドに依存する必要がなくなった
  2. Doctrine ORM 3.xとの互換性問題

  3. 実際の使用状況

    • コアシステムでの使用例が見つからない
    • プラグインでの使用も確認されず

変更内容

1. __set() メソッド

  • 変更前: 無条件にInvalidArgumentExceptionをスロー
  • 変更後: Doctrine ORM 3.xのプロパティ初期化を許可(コメントのみ)

2. getConstantValue() メソッド

  • 呼び出し時にE_USER_DEPRECATED警告を発生
  • PHP 8.2+のtrait定数機能への移行を促すメッセージを表示
@trigger_error(
    sprintf(
        'The enum-like property access mechanism is deprecated. Use PHP 8.2+ trait constants instead: trait MyTrait { public const %s = value; }',
        $name
    ),
    E_USER_DEPRECATED
);

移行ガイド

旧実装(非推奨)

trait CustomerStatusTrait {
    private static $LEAVE = 3;
}

class CustomerStatus extends AbstractMasterEntity {
    use CustomerStatusTrait;
}

echo CustomerStatus::LEAVE();  // __callStatic()経由

新実装(PHP 8.2+推奨)

trait CustomerStatusTrait {
    public const LEAVE = 3;
}

class CustomerStatus extends AbstractMasterEntity {
    use CustomerStatusTrait;
}

echo CustomerStatus::LEAVE;  // 直接アクセス

影響範囲

  • コアシステム: 影響なし(使用されていない)
  • 既存プラグイン: 理論上は影響する可能性があるが、使用例は確認されず
  • 後方互換性: 機能は維持されるが、非推奨警告が表示される

関連Issue/PR

テスト

既存のテストは引き続き動作しますが、E_USER_DEPRECATED警告が発生します。

🤖 Generated with Claude Code

AbstractMasterEntityのenum風プロパティアクセス機能を非推奨化:
- PHP 8.2以降はtraitでクラス定数を直接定義可能
- Doctrine ORM 3.xの__set()との互換性問題を解消
- getConstantValue()呼び出し時にE_USER_DEPRECATEDを発生

Changes:
- __set()メソッドから例外スローを削除し、Doctrine ORM 3.xのlazy ghost objectsと互換性を確保
- getConstantValue()に@trigger_error()を追加し、使用時に非推奨警告を表示
- PHP 8.2+のtrait定数機能への移行を推奨

Refs EC-CUBE#6469

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@nanasess nanasess changed the base branch from 4.1 to 4.3 October 3, 2025 06:58
@nanasess nanasess enabled auto-merge October 3, 2025 06:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants