Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122971 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 3F4691A009C for ; Fri, 5 Apr 2024 14:20:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1712326882; bh=QxSfC4RIJED9BhIx6UX7hguBs0D1eWF7Ltpw3k5MhdI=; h=References:In-Reply-To:From:Date:Subject:To:From; b=Z0zD7EdYf0D1MW77W3P1+kcPtlHM1Ex+zBOAzQzw9XSO65VgwgyP1QazSBq74Oc/X 9tWoXtuAYPSy2HM/voDq+UUwZodEPmvF4cgk9S4TKFyK8kyxJ58vDoQ8pwLAP501Oh Pa3ViC+6M1qPIYol1cgUkR33Rvbba0Wyl2lLCQrJTVw5rBSx+I7+7K0anN7XMtLXuc M64LVbHF3H++5Nd5UvhA4gP1jJabVcN441zGLnvKlu6RMWi42WbiQl1AYOroxmU8Ek F5DHMd0wLvuECh62wOoF60Zl2GjreDvJKr/LRYhSOJSzdW2DL/1bVoU9QieF0Jzobl q1yjICwOZnelQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 4E539180907 for ; Fri, 5 Apr 2024 14:21:21 +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,HTML_MESSAGE, 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: No X-Envelope-From: Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.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 ; Fri, 5 Apr 2024 14:21:20 +0000 (UTC) Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-a4702457ccbso305617166b.3 for ; Fri, 05 Apr 2024 07:20:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jolicode.com; s=google; t=1712326849; x=1712931649; 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=NFCuIC3ctKJo2Y03LsutmjMS404yCns6WRB4ccFkOKc=; b=Rm84oI3eZngS32dJqg/Pp75Vk+cmnn2PN5E74e7r7+ZDyja6bhSwvH7SAQjlsDEu0c 0oF15DXwSnoAhvEhxpVg2FqHotg1w+81gy9bdtIAg9I9DLhRactVpauZXwvuiwZO5QiS SokXAO40zpisJM0U8A69HH/7fYmD8E//v7H+Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712326849; x=1712931649; 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=NFCuIC3ctKJo2Y03LsutmjMS404yCns6WRB4ccFkOKc=; b=MTNHtHOqSet3qeDAzXoppFlz3QJY6WLl8DBTcHwzYfNK5PpgLA6cp1Qn+PO8i7UHZi 3g/D2jPm203LNJ/KdVUjYSAWgTv27Iq/bv4jlt7l5+Qfyk/F+LjvKzvPzpf/Lx+BtHxe dy5fSrqb/sSqL4y4O+FNvgxh1dnMLBclHo057uAnFGw/Mfptof+f98E5mZApv5P13h9h CeGG4wEmoxxUHp0B3d3uRsMNyKfSzKOen2xEux5FeoR2qqm69SAeD7mEx4KGUArFVYcs UelC5E0o6fSGp4qrONz6N9EKoy6L4y9y7xKULPdPVpFN8phN3RxxHpcMBOXK4dOQ4Xnd yjsg== X-Gm-Message-State: AOJu0YwrVHiIaUqZ6ArOFzDbegHrmpbZOcI6XF7x225+IgZ7c8aX+Rf7 BouMvL1jz0FX7r9QPygTfACSwaj3h1h0AqaAN/iyGgsGdw+orHUnpSxaCKf4ugbqW7b0MBzC5w6 98dF1C+wbBy20/JyWcTtk7JLdvfn9j5WLiDdLd+hbCvgWkWK+n7KPuQ== X-Google-Smtp-Source: AGHT+IG4qBy+RpPJ36Alr/XnBTZn/otM7vHUHtrPMf4dgTYIg7rBCsQk2CJevH1mThik70amfeQRo42JFkx2/vE4hho= X-Received: by 2002:a17:906:709:b0:a4e:23bf:77e8 with SMTP id y9-20020a170906070900b00a4e23bf77e8mr1122908ejb.72.1712326849206; Fri, 05 Apr 2024 07:20:49 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 5 Apr 2024 16:20:38 +0200 Message-ID: Subject: Re: [PHP-DEV] Proposal: retrieve line, filename and if user defined for ReflectionAttribute To: PHP internals Content-Type: multipart/alternative; boundary="00000000000096392606155a29dc" From: jwurtz@jolicode.com (Joel Wurtz) --00000000000096392606155a29dc Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable > Would it make sense to not only add this for ReflectionAttribute, but also Function and/or others? There may be case where this makes sense but not necessarily in the use case that i explain, and don't want to add more to this proposal, it's also missing in ReflectionParameter, ReflectionProperty and certainly many others if we go on this path then there is a lot of changes to apply and will induce more friction for this proposal, i prefer to add small parts so we don't deviate from the original use case. > Do you have an example of how you expect this to be used? I'm having a hard time understanding how I'd leverage this. (I maintain an attribute enhancement library, Crell/AttributeUtils, so I've hit a lot of edge cases in attribute design.) Sure, let's say we have the following class #[CustomAttribute(foo: 'foo') #[CustomAttribute(foo: 'foo') class Entity {} And that later i have something that read those attributes, but i want to throw an Exception when multiple attribute defined the same value for the foo property (as it should be unique in my use case), i would not be able to do that in the constructor since i don't have the context of others attributes in this case, so i want to throw a custom exception explaining it's caused by the attribute "CustomAttribute" in the file "Entity.php" at line 4, as there is the same value in the file "Entity.php" at line 3 If I throw an exception without this message the error will pinpoint to where I threw the exception and it may be confusing for the end user, by having this he will know where to look and what to modify to make its code correct. > I would propose negating and renaming isUserDefined() to isInternal() Both methods exists depending the context (there is a isUserDefined() in the ReflectionClass class), but i'm fine with negating this if it's more consistent > As hinted in the PR, I believe the implementation is wrong, I think the implementation is correct, i answered in the PR, i will add more tests case that explain what is wanted here > I'm also wondering whether it may be more useful to expose the attribute class as getClass() Do we not already have this with the getName() method ? or it can be wrong if it's an alias by example ? Jo=C3=ABl --00000000000096392606155a29dc Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
> Would it make sense t= o not only add this for ReflectionAttribute, but also Function and/or other= s?

There may be case where this makes sense but not necessarily in the use case=20 that i explain, and don't want to add more to this proposal, it's a= lso=20 missing in ReflectionParameter, ReflectionProperty and certainly many=20 others if we go on this path then there is a lot of changes to apply and will induce more friction for this proposal, i prefer to add small=20 parts so we don't deviate from the original use case.

> Do yo= u have an example of how you expect this to be used?=C2=A0 I'm having a= =20 hard time understanding how I'd leverage this.=C2=A0 (I maintain an att= ribute enhancement library, Crell/AttributeUtils, so I've hit a lot of edge= =20 cases in attribute design.)

Sure, let's say we have the fo= llowing class

#[CustomAttribute(foo: 'foo')
#[CustomAttribute(foo: 'foo')
class Entity {}

And that later i have something that read those attributes, but i want to=20 throw an Exception when multiple attribute defined the same value for=20 the foo property (as it should be unique in my use case), i would not be ab= le to do=20 that in the constructor since i don't have the context of others=20 attributes in this case, so i want to throw a custom exception explaining i= t's caused by the attribute "CustomAttribute" in the file "Entity.php" at line 4, as there is the same value in t= he=20 file "Entity.php" at line 3

If I throw an= =20 exception without this message the error will pinpoint to where I threw=20 the exception and it may be confusing for the end user, by having this he w= ill know where to look and what to modify to make its code correct.

= > I would propose negating and renaming isUserDefined() to isInternal()<= br>
Both methods exists depending the context (there is a isU= serDefined() in the ReflectionClass class), but i'm fine with negating = this if it's more consistent

> As hinted in the PR, I believe the implementation is wrong,

I think the implemen= tation is correct, i answered in the PR, i will add more tests case that ex= plain what is wanted here

> I'm also wondering whether it may= be more useful to expose the attribute class as getClass()

Do we not already have this with the getName() method ? or it can be wro= ng if it's an alias by example ?

Jo=C3=ABl
<= /div>
--00000000000096392606155a29dc--