php / php/php-src

Abstract properties (hooks) in traits

オープン
#19,504 コメント 10 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Category: Engine Feature Status: Verified
主要言語
C
スター
40.4k
フォーク
8.2k
平均マージ
2日 15時間
マージ済み PR(30日)
103

説明

Description

At the moment such code does not work (8.4 and 8.5/master), which does not seem very logical:

<?php

trait Example
{
    abstract public string $property {
        get; 
    }
}

class ExampleImpl
{
    use Example;
    
    public function __construct(
        public readonly string $property,
    ) {}
}

Produces:

Fatal error: ExampleImpl and Example define the same hooked property ($property) in the composition of ExampleImpl. Conflict resolution between hooked properties is currently not supported. Class was composed

https://3v4l.org/UYnbo

According to RFC (https://wiki.php.net/rfc/property-hooks#interaction_with_traits), traits do not actually support properties, but at least such primitive conflict resolution would be nice to have.


P.S. Is it worth writing to internals for RFC if there is no way to send a PR?

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

提供されている trait と hooked property の再現例から始め、続いて trait interaction に関する property-hooks RFC のセクションを読んでください。trait の合成が abstract hooked property と implementing constructor-promoted property をどのように扱うかを追跡してください。報告された競合なしで例を合成でき、意図された property-hook の動作が維持されていれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
php
領域
compilers
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
30/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。