Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123349 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 A53E51A009C for ; Sat, 18 May 2024 15:14:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1716045349; bh=VSaiXd5isf87PNvNrZaWnwPESPFydEGCs3FXDzXwcEM=; h=Date:Subject:To:References:From:In-Reply-To:From; b=jo107ZGc7rs4PnuWWpqJgeefbSoiUQ25Y1BF4uhWAL56HZvmX98NrDuTLwg2Pfc9Y OxXcz5SNXGsCNL71tW4FB8tsEtKFLQEikylzCQ2lZbCgO7Ov/95a/oA9NEr5xNSh44 Ju/1BL9+o9R46h1HMsaP4oIeqICKXrfa1qvnujks8qFLCiYIXui+6X+Aw3OPrNfUyd wz1DTAaxEc+oATQtT7oz0qOKkHJIFzAQUouPBXHmc8aABY+fLIMs3CnqG5vpFzspJs UA3xXaTzRVzouYZ7z6X8IFCFy1rhNpz2se+4XaWldcYQoDlE6xptSGKO/m10u8V1zG /XnrqfjjsCg5A== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2E3281806BA for ; Sat, 18 May 2024 15:15:48 +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.1 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,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 wfhigh4-smtp.messagingengine.com (wfhigh4-smtp.messagingengine.com [64.147.123.155]) (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:15:47 +0000 (UTC) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.west.internal (Postfix) with ESMTP id 8F58A1800113 for ; Sat, 18 May 2024 11:14:52 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Sat, 18 May 2024 11:14:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rwec.co.uk; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1716045292; x=1716131692; bh=2sFTH2SvmQ sSRIHBwPhPkZzODkfoTV7Ls+9zN59F9+A=; b=mX7N4fIoD2ApynWG5ym+fZRQ7v VVxwCElaO0fyxp+WKNrcUWGZzaKcPmHrkdJ+kPJgHnFTfKGs3da+fEZlDK6BbbDd oSGO/9E7I32QBrF+Q/2bVTj73FpnVM0uPLNjpds1vt20Qxjo4/iWtPuzXK+UA2FF AzDB+zJTxD3O73G6torbkxm0NqXrPAQZ3tn6HbSi0hwqow+WcF+RkVsa+d6axvzh D2wpVswE3X56KhOJb2xQS9EwpelOKHBmVv9wOESMbIwceeCKBx9uho5qEqHv9/yV ySPjqUISXPsBwNPYC4Yw+LS/emdtYC97zrhJXsQlzZJdkKyRSIduAcS4WKew== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1716045292; x=1716131692; bh=2sFTH2SvmQsSRIHBwPhPkZzODkfo TV7Ls+9zN59F9+A=; b=nynGcOpfFW8cz2PZ4lT7gX1iwKQ66uswzqWBsPf37eVX Qh+6xOviaxhBAvbNhkj682GdBs8QQEp3GMhPkNjGVqOQHYKnDHr/+Ki22+w26gu6 j0pX9kB7wAcQ+WzqZ2YMTzY2EG/ldZ2usZpR1mj6STWACQG8e/Rp8WihXLPFyq0A MSGHbFH7EcTuLQG+SIy3rgQ5LxWdR/aCvWNNO4gQbX9ud4nkcsUAZ2jx2czuaql2 XUXKEFN7lZBH32InYqcoLcJApjkoxfXicZzgcXU3DvJ2L/9iOabE83hwyAkRYZsl 83WNQ9ytZ61o/f2mFYQ25V+vzY8xJRyDOVIiKwLy/Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdehiedgieelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpegtkfffgggfuffvfhfhjgesrgdtre ertddvjeenucfhrhhomhepfdftohifrghnucfvohhmmhhinhhsucglkffoufhorfgnfdcu oehimhhsohhprdhphhhpsehrfigvtgdrtghordhukheqnecuggftrfgrthhtvghrnhephe etleeiiefgueduieeuieffvdevheduueefkeejuefgffeftdeitdegtedtleetnecuvehl uhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepihhmshhophdrph hhphesrhifvggtrdgtohdruhhk X-ME-Proxy: Feedback-ID: id5114917:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Sat, 18 May 2024 11:14:51 -0400 (EDT) Content-Type: multipart/alternative; boundary="------------82O05yHVXD8dZ7f1lLmwYhWY" Message-ID: <69669f3c-8e9e-4f27-a171-6c341c1d67f7@rwec.co.uk> Date: Sat, 18 May 2024 16:14:48 +0100 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] [Discussion] "Internal" attribute and warning To: internals@lists.php.net References: Content-Language: en-GB In-Reply-To: From: imsop.php@rwec.co.uk ("Rowan Tommins [IMSoP]") This is a multi-part message in MIME format. --------------82O05yHVXD8dZ7f1lLmwYhWY Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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 namespace" is the best semantics. It's very common for the top-level namespace to represent a vendor, and the *second* level to be the specific package, e.g. Doctrine\DBAL vs Doctrine\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 cases, there are more levels - e.g. Composer package "doctrine/mongodb-odm" has root namespace "Doctrine\ODM\MongoDB". Possibly the attribute would need some argument to specify its granularity, e.g.  #[Internal('\MyCompany\PackageA')], #[Internal('\Doctrine\ODM\MongoDB')], but that would be annoying to write each time. This is another case where PHP suffers from its lack of a separate concept of "package" or "module" to scope things to. My second concern is how to implement this efficiently. The check can't happen at compile-time, because we don't know the definition of SomeOtherNamespace\Foo; so the check would need to be at run-time when the method/function is called. But at run-time, namespaces have very little existence - they 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 the calling function or the class name of the calling method, and then do a string comparison against the namespace constraint. Maybe that would be easy and fast, I don't know. Regards, -- Rowan Tommins [IMSoP] --------------82O05yHVXD8dZ7f1lLmwYhWY Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
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 namespace" is the best semantics. 

It's very common for the top-level namespace to represent a vendor, and the *second* level to be the specific package, e.g. Doctrine\DBAL vs Doctrine\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 cases, there are more levels - e.g. Composer package "doctrine/mongodb-odm" has root namespace "Doctrine\ODM\MongoDB".

Possibly the attribute would need some argument to specify its granularity, e.g.  #[Internal('\MyCompany\PackageA')], #[Internal('\Doctrine\ODM\MongoDB')], but that would be annoying to write each time.

This is another case where PHP suffers from its lack of a separate concept of "package" or "module" to scope things to.


My second concern is how to implement this efficiently. The check can't happen at compile-time, because we don't know the definition of SomeOtherNamespace\Foo; so the check would need to be at run-time when the method/function is called. But at run-time, namespaces have very little existence - they 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 the calling function or the class name of the calling method, and then do a string comparison against the namespace constraint. Maybe that would be easy and fast, I don't know.

Regards,

-- 
Rowan Tommins
[IMSoP]
--------------82O05yHVXD8dZ7f1lLmwYhWY--