Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123361 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 E3B181A009C for ; Sun, 19 May 2024 07:45:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1716104796; bh=YE1MWo/92Qegvf8JgQTBuzywauppPV+SKVhWADqemYw=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=GGh9RvhTkVdpPWTb27kmcXax3QZ7kiepESyxo0qN1gdElhxgYWJyufCKyaaKeRJYX l7FT3jfwK6CA0cKVwKvX0d4jHEY9Lw+4Fo26TFOsPZQA3FTm1fsyILV2YJBbcn5/77 m3zPoTFfcdam4zMpXUrs4YsGVdOu5GPFwMwpN68lgJwN8snqiVf4GCBx0BDF0bg7li E8quEaWn5bBWFCgMf56M1hqyWD2fA9MuwWgk7X+qs2oPEB7b3CfzWYY7fpYLGLNvUE whnW4iedHGGC6zBsux32S+0cZS/tv4PspRSwlq00DQ+Rg+wZzv5QWWEgP2puhc9bzJ DxikTn9qzKuaA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 6135D180004 for ; Sun, 19 May 2024 07:46:35 +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.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,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-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) (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 ; Sun, 19 May 2024 07:46:35 +0000 (UTC) Received: by mail-lf1-f49.google.com with SMTP id 2adb3069b0e04-51f72a29f13so2529096e87.3 for ; Sun, 19 May 2024 00:45:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716104739; x=1716709539; darn=lists.php.net; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=JlzZY5XnbQxwHCfhTqwZzz8VxVB9qypjDCmN7HHBSXE=; b=h3sH5oh+4p5ZSwb2JdUmDR1uM9CTUgHaMQWoRBTf2V0Hgwy1nfbAW3Bo3KbiXmEXmC ZQKKdfRap+QUfbT35mybQjYZoh1O0jldNXk/W/nYFeD+AWxZbWtywG7/x+y/zwWMYLQ1 N+fBnztT5TVC5layMtJeiha8wCMx5IZHriTE+xjP53WFiXeWc/SO+fjLkk9kl8BURt7r +pE4BNpdy/H3JlvXF9WO15pwBAHI2VR6l9vfYvmeKuPgV2zVy0c11HBlMnWoWBSVAvmr bqvMR8sk7tJLHf6+vBmt3lBfjyi4qYD+kfnYYWqIUUmY+UXy7R0eWTama7a5hNR02ccM 7tKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716104739; x=1716709539; h=content-transfer-encoding:cc: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=JlzZY5XnbQxwHCfhTqwZzz8VxVB9qypjDCmN7HHBSXE=; b=auhWS3iLHsKYfH4FtYWKzUIssbVIrwuCzri3BhS15naMQQPll3fVT6VD/tCmP5RY+M enUFyTC6k1sRlj2xWf4qTnQy6RuoY2U6NwGFYbXEBUTX9gTPaLzvgcVmBpq+i18CRo8X eNrGp2l7yt3pWt/WoE1aYTG3CsueVJz47l2oiMEXjed7mSx+soSbP3ASMs7y0qEFdivo d+Z0ZBMcUisRMzI59FQdXZs/uYJlo9esAelAtmBzMMN0lkKjw78ffOXrsS95d4fu1s+Z llk9Ad8tmJeph2SEkcP9FnB6cVbALbHjYo5L2VkfiLYyaOopriTQyoAMzhkXaW5Gj0Uo TbtA== X-Gm-Message-State: AOJu0YwVBgfi+MPq8b6iKEZpGGMM7J9f1mq4csufZHXlLjmjycYt7/5G vpM2LuPW1O4kgUDDJQqqGNR2/Su3NG7r+H6CmWup7oI2cpec8dOzrY5wbI1d+rXvZTUKmdzytUs vbP69XYHRBKubx1cmn/DXygYIx0iBmZf3+8s= X-Google-Smtp-Source: AGHT+IHikTz8RdVBUpdSbTuBUz8ynyX6tgPlfSdOIueqgAx0tzHUKm49yFgE4IYMf097TA5rlHj9jyoiOkpc9DHBf04= X-Received: by 2002:a05:6512:23a2:b0:523:97ee:c1f4 with SMTP id 2adb3069b0e04-52397eec322mr10613723e87.56.1716104738826; Sun, 19 May 2024 00:45:38 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 References: <35f6f3ce-fc7d-4911-8a1a-a06f8e17fe71@barneylaurance.uk> In-Reply-To: <35f6f3ce-fc7d-4911-8a1a-a06f8e17fe71@barneylaurance.uk> Date: Sun, 19 May 2024 09:45:26 +0200 Message-ID: Subject: Re: [PHP-DEV] [Discussion] "Internal" attribute and warning To: Barney Laurance Cc: internals@lists.php.net Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: landers.robert@gmail.com (Robert Landers) On Sat, May 18, 2024 at 10:33=E2=80=AFPM Barney Laurance wrote: > > On 18/05/2024 15:00, Robert Landers wrote: > > Hello internals, > > > > I've been thinking about having an "internal" attribute that will emit > > a warning if called from outside it's left-most namespace. > > Hello Robert, > > It's worth looking at the prior art on this - the @internal annotation > from PHPDoc, and its implementation PSalm, PhpStorm, and also the > @psalm-internal annotation, which I added to Psalm. @internal requires > the leftmost namespace segment to match between declaration and > reference, while @psalm-internal is used with a specification of the > namespace to which the annotated element is internal, which may be a > deeply nested namespace. > > I had the idea to create @psalm-internal originally because the Drupal > project was recommending plugin and site developers create independent > work within the Drupal namespace, while having certain elements > documented as internal in the Drupal\Core namespace, with breaking > changes in point releases. > > Another prominent left-most namespace with code developed by people who > might like a tool to help them avoid depending on each other's internals > is League, as in https://thephpleague.com/ > > I think if something like this is added to the language it would be a > shame not to give it something like the flexibility of @psalm-internal, > instead of only dealing with the left-most namespace part. > > See > > https://docs.phpdoc.org/latest/guide/references/phpdoc/tags/internal.html > https://psalm.dev/docs/annotating_code/supported_annotations/ > > I'm not currently a PHPStan user, but from what I read PHPStan doesn't > have this feature but has started considering it: > https://github.com/phpstan/phpstan/issues/1178 Thanks Barney, Yeah, I think having an optional parameter to specify the namespace the class/function is internal to would be immensely useful on bigger/complex codebases. It'd be annoying to spell it out, but so long as the attribute definition isn't marked as final, people would be able to extend it with defaults: #[Attribute] class InternalToMyPackage extends Internal { public function __construct() { parent::__construct("\MyPackage\Deeply\Nested"); } } Robert Landers Software Engineer Utrecht NL