Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123881 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 9D3801A009C for ; Wed, 26 Jun 2024 19:16:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1719429473; bh=m94n6uwgD8ednw01Nnl4F48Vsv0w/eS5CffAdTcmJq0=; h=References:In-Reply-To:From:Date:Subject:To:From; b=UVxGtJvTlEg3TMnGR21XhBKzOEzTAzBf/978vXN0j1RZeIl6Ba1kAn24e/uAcpCQ/ ivBeEIFWE4Nx3kBAzZjGi708mPSfxaFxTqyE93PZEdNkwglixt8TkhdoTLolzuYRlq J1yAg/2YZBogLocFeOpE63hF3LRziA0wvUTRv0T58AzPYFuizGrM/dpcqtNtUkpHtz 5W8tMVuFU/KL371SanTBz9yB2bL1OugD3WD7HRx03Ji58GtJ4r2i9ht3jYTlwX9u80 y9QAQXKn7QZVO+leQi4TBTt0UTd6qPnCr3Gk1AMGBNVd7ZGkjA5PmVQBCGR7a7R2fh HuVmAnpS5n8Bg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 53812181444 for ; Wed, 26 Jun 2024 19:17:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 26 Jun 2024 19:17:51 +0000 (UTC) Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-52ce6c93103so4821975e87.3 for ; Wed, 26 Jun 2024 12:16:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719429392; x=1720034192; darn=lists.php.net; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=7lwVY/+oTIZPOcPQfpsMtDkiuJD82kzjebCf3IDV1Mk=; b=DgI/5GxqaKflb/5A2r08IkBFDjz1G+/iEcb5qQyHBQsjsKbPJklQ8eoC31pPk1PehY 6+K4yVyW21iItbg5O34RTMDkobXCpg33ydiFpuVBmJ/TN0f3/1idUNaPxOwzKTE4+lDo 1SgXzj575ToZ353a8F2tasIzqkCi68igcQDh30t18ncD0DoK/hKJzFN6WyIKOB32VzHd E/bAxSvjRBnNIlNpwNbwPodFT0084ewyDsFjCDxNVpySzLDrORQgfdDc/ydlSHgVtZh6 vb2u4ZRBKOzGMTro56ZizU8Oof6CroGXH3KijmEd78sj8cfynSb/qpqLv1EyyATpR92l S+iQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719429392; x=1720034192; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=7lwVY/+oTIZPOcPQfpsMtDkiuJD82kzjebCf3IDV1Mk=; b=obXxOzaL+Ezfd10oskKfmYxDvUUOvl1zfW0oMbOdgBYw3RcPdgiEiDODAKNwRGCOXY /6WuhSOO8xNEYt6coDiVKvzL37nlqBZbUu8nqbyAhVx+bAqQIwjQiwBObV+5xfwlCZgt dSpDA8R555h0LbyZwnX1BqVvW2qfzNnHvhUmrrYkaMof38IcoSG3dZMakXjhQsslmh7M ftjUJA1TqUIH9IKaGvcE96Lk4n4FNIxWRjNo0B77/lopR9focbkttXcyqWh/1974IBbj 8ftKnPhXoap7c4g1CT0qr7YNhwVSkQMXdg2YJ7QGfraCqKjMjD3ptUHUEV4ywddimW4T VerQ== X-Gm-Message-State: AOJu0YzYf2ctpEX4/c97fH9dyUcrVp3W6gGDeP/iRFVHdbnYpSu3ZMaF IakE5WXCzHzbakM8qbTOAs2I20pw3VMO0jTczJRROSoZZATW8uQ0AJLhsPOhTefXvJ8PeFgfozh TylJghJIGTJ3Lh61hh1Z7Jn9yXDhS4eZw X-Google-Smtp-Source: AGHT+IEUbVbp3CdT9/bWs+dPmtTZ/2Wbn2e93lAisyShF2e7qdyDZ81bBHxMSOt1LKHiR5LmG0RU1D+hD/dtqDq/FeI= X-Received: by 2002:a05:6512:2031:b0:52c:e119:7f1 with SMTP id 2adb3069b0e04-52ce185273amr7191347e87.51.1719429392062; Wed, 26 Jun 2024 12:16:32 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 References: <667B35B7.4070902@adviesenzo.nl> In-Reply-To: Date: Wed, 26 Jun 2024 13:16:22 -0600 Message-ID: Subject: Re: [PHP-DEV] Add $this return type To: internals@lists.php.net Content-Type: text/plain; charset="UTF-8" From: radar3301@gmail.com (radar3301) Juliette Reinders Folmer said: > Not a fan of using a variable as a return type. This will cause > havoc for Tokenizer based static analysis tooling. I will concede that until the tools are updated to handle the new (currently invalid) syntax, it would cause issues. But that happens everytime a new syntax is introduced into PHP anyway (the original return-types RFC, match, the proposed property accessors, etc.), so I'm a bit confused as why this is an issue that would stop the RFC? --- Juliette Reinders Folmer said: > Also don't really see the need as there is the `static` return type > already. To quote Nicolas, who said it far better than I could: > I tried switching from the `@return $this` annotation to > `function (): static`, which is the closest approximation currently > supported by the engine, when I realized that this would loosen the > semantics of the corresponding interfaces[.] --- Marco Pivetta said: > I'd see it as useful if the type conveyed identity too, although it > means that I would never use it, since I design immutable APIs, when > possible :D If reading documentation, I'd argue that seeing `function(): $this` in a class already conveys plenty of "identity". If you're talking about using the Reflection API to get identity the original RFC by Nikita stated: > The `$this` type is a subtype of `static`. As such, it is possible > to restrict a `static` type to `$this` in a subclass (but not the > other way around). > In reflection, the `$this` type is represented as a > `ReflectionNamedType` with `isBuiltin() == true` and > `getName() == "$this"`. So perhaps a change is needed in the returned `ReflectionNamedType` to better identity the actual class of `$this`? Or am I missing your point about identity here? --- Bruce Weirdan said: >> Luigi Cardamone wrote: >> Is it possible to replace "$this" with "this"? Cleaner and coherent >> with "self". > > That wouldn't be possible, as `this` is a valid class name: The "Return Type Declarations", "Scalar Type Declarations", "Reserve More Types", and "Void Return Type" RFCs all prohibited their usage as class, interface and trait names. Using `this` or `same` or `whatever` else is decided is just par for the course. However, that said, a search of github for: - `language:php "class This "` returns 5.1k results (but it appears that most results are docblock comments) - `language:php "class This extends"` returns 27 results - `language:php "class This implements"` returns 8 results - `language:php "class Same "` returns 290 results - `language:php "class Same extends"` returns 193 results - `language:php "class Same implements"` returns 14 results - `language:php "@return $this"` returns 485k results. --- Regards, radar3301