Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123350 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 E3F4B1A009C for ; Sat, 18 May 2024 15:25:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1716045978; bh=5uPnekFTRqju2+Fya46qUK9OqDfBo21OAeifapL+aCY=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=C2jeLP9qYOQNmInf/KfMSkmL3qtKZb7rGaTB/qMiZdUMhq7aHueCp897kX6To+fLg p3e0ishNOBxN0E6lHEtNLz+O/6yy1ccQNsVogVa+7TA0eT19PImdAcUEzbmd/n7l/4 FCHOi9AqGtxeWaaWnIMPjkhluOPEJUcaGbY6A2+t9ygPVcvQ3tzVE2RAySxt/6VLOf ORwb6yEh/nwqkW8W46zYqZpj1BnO54vW/7XlpQzKVzoHIqIbTgjBvDRr3YKpXTG4Bl bnlO/gy5vLs2RZzSgTwJYxu455KbOO3qrTJQaK1da1Wqy6ZDuSBltBbcK0EpypEyBE WgO9KoLd2SRWQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id CCD8318092C for ; Sat, 18 May 2024 15:26:16 +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-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) (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 ; Sat, 18 May 2024 15:26:16 +0000 (UTC) Received: by mail-lf1-f47.google.com with SMTP id 2adb3069b0e04-51f74fa2a82so1885334e87.0 for ; Sat, 18 May 2024 08:25:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716045921; x=1716650721; 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=xf19231Uu3X/Gsh2UnWuLP4npgGTq3mXxD7mlLJj1qQ=; b=IPAaBDO6KxHfh+mlmqS8w/BAEeO16hKcnbBP5b1VJXSemu6Wbe46j3NCOk0nApPKgB em8yS5nzOODM7L4dzgkiCYGKcUwxWMAsNMx1rr6TrLkDpkZblPS7DjYWFt+G95L09S7B 2bJiXgZNxLopFV00TBQsp5/nNxec+JtABHMNBPsmUBtCsEqab/uNx6A80IV6M+mgwZ+v wG05dNHZMVOw2Gt//tqGwAju5v7VZBagZxf4rYuyTcAc2pMAwE3gJfQan4TYTvkxaxh4 ueKQKoRWEdRr6hVgN7NyK7/tkCY9ke9yiW3dFOB+oqo6a5sBLMK/DZILUUFCjzMPEre8 ACNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716045921; x=1716650721; 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=xf19231Uu3X/Gsh2UnWuLP4npgGTq3mXxD7mlLJj1qQ=; b=qkXyBSYbnx9Y73IFn8xH+XHAKacxEajKCQ+6/fvgrtNcXjZ5bIP+OAnThW7o2IuY6V PsHzSHU+IubPp8vC3ZeVjQ7GCFaNy71jhFV/Wi6RT95QE5dTqBC/3c1U6Ww8qNvMFFlR CGeAR3BN0hiW4UqESo0g9tIMJcHw2uk0qYvzodzkVoF+uA7aNJWEtoFDZAd7x7qvNX4Y tFp1on1IRIN3eWuHNb54YcfpGoMqx+0c9M5Fv2ZjHFtKjWOPLYe2Z0DWya5nhwmDvRI/ /S39StuNvq3VMP3k5d8clf9/eNlrDa9LVOzACQQqdsE//hdOrjEl21gz9/auhHpWQwrF LXwg== X-Gm-Message-State: AOJu0YzbCY1KluLpRjm8yJCpPlznYXvsKdh7mzkOOFbjIpfqQFYdRzyx AHeTjjrIez4azgE0DSCNXDDe9YzxNNDKQoJiBjA3TUrBhwB8UBy0ch6UyTiJPb8rgW388lV85Aa R8jeiHBD54sjCPJ9DUtkvFe0PwiRuwBTZ X-Google-Smtp-Source: AGHT+IFTv3iB9kTDWcvEmLBOLkmcf7wSrqOumEu7Kf22PCy8P+OZJurZVV8ZFTrb/PvKzdb96VakqzqEAqPfzIqS0Q0= X-Received: by 2002:a05:6512:475:b0:51a:d08d:bab4 with SMTP id 2adb3069b0e04-5221016b518mr20084971e87.55.1716045920447; Sat, 18 May 2024 08:25:20 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 References: <69669f3c-8e9e-4f27-a171-6c341c1d67f7@rwec.co.uk> In-Reply-To: <69669f3c-8e9e-4f27-a171-6c341c1d67f7@rwec.co.uk> Date: Sat, 18 May 2024 17:25:06 +0200 Message-ID: Subject: Re: [PHP-DEV] [Discussion] "Internal" attribute and warning To: "Rowan Tommins [IMSoP]" 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 5:18=E2=80=AFPM Rowan Tommins [IMSoP] wrote: > > On 18/05/2024 15:00, Robert Landers wrote: > > I've been thinking about having an "internal" attribute that will emit > a warning if called from outside it's left-most namespace. > > > I like the general idea, but I don't think limiting to "left-most namespa= ce" is the best semantics. > > It's very common for the top-level namespace to represent a vendor, and t= he *second* level to be the specific package, e.g. Doctrine\DBAL vs Doctrin= e\ORM. You've even used that in your example - I presume you've made a typo= , and meant both examples to be calling PackageA not PackageB. In other cas= es, there are more levels - e.g. Composer package "doctrine/mongodb-odm" ha= s root namespace "Doctrine\ODM\MongoDB". I thought about that too, but in-general, a vendor has the knowledge and capability to ensure any two packages work together (like Doctrine plugins in your example). > > Possibly the attribute would need some argument to specify its granularit= y, e.g. #[Internal('\MyCompany\PackageA')], #[Internal('\Doctrine\ODM\Mong= oDB')], but that would be annoying to write each time. > That could be a useful optional parameter, and might be worth considering. > This is another case where PHP suffers from its lack of a separate concep= t of "package" or "module" to scope things to. > > > My second concern is how to implement this efficiently. The check can't h= appen at compile-time, because we don't know the definition of SomeOtherNam= espace\Foo; so the check would need to be at run-time when the method/funct= ion is called. But at run-time, namespaces have very little existence - the= y really are just part of the names of functions, classes, and constants. > > So when calling a marked function, we would have to look up the name of t= he calling function or the class name of the calling method, and then do a = string comparison against the namespace constraint. Maybe that would be eas= y and fast, I don't know. This is a concern of mine as well, but I'm mostly curious if anyone even wants this before I worry about implementation details. Right now, I don't see it being any slower than type-checking, though I foresee a bit more memory usage to keep track of the caller/callee namespace. > > Regards, > > -- > Rowan Tommins > [IMSoP]