Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128087 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 lists.php.net (Postfix) with ESMTPS id A3AF41A00BC for ; Wed, 16 Jul 2025 16:41:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1752683974; bh=tfKWGkbaJmAselEW/EK9/PhFaxxgjl+0q5MD2NFzRy8=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=SyaWAgA5ASymA7lVSpnMHisguM2kGeqdlZ5FN2F+Jvp0BSO7CRo3PLKmAISWTnTUG WFDeTgpn8Lp9WqmoSAxagDLT88OrpAsL8sxApr7vHAhNme5SqWYxp0Giliq5C8n+XX 3C6X4moONdQHmxwFnYkARpI/8BbU4UOtsHWkh8Ps3fgAuCvyddVRauhQ5JO1nnjeRK aPkzNlmhoaLm8i1ohiMzL39s9VGdmEoCDyJjoGwHONR94HTwvvR9fyLVcWQ/J9HuzZ iiyrjMfhL4OaJkv0XRv9G3iVzXzL8H/vqCI0fHEwk/OosVgqSadOjjVBlOiV6RNnRl SUxIkPTmXEvdA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 488AD18004D for ; Wed, 16 Jul 2025 16:39:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.4 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from mail-yb1-f171.google.com (mail-yb1-f171.google.com [209.85.219.171]) (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, 16 Jul 2025 16:39:34 +0000 (UTC) Received: by mail-yb1-f171.google.com with SMTP id 3f1490d57ef6-e8b802286efso11253276.3 for ; Wed, 16 Jul 2025 09:41:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1752684081; x=1753288881; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=22lUn29S/TzuzXNANcDpHY5ZmO3RcDfXmK71AuEKaTU=; b=LrSpuInek+VrcMUraEe0/g8hw/3Yj4RilvH3V5+8nWCCk9GipJ0qr8w+aSMc09Xazx YsyHjQTZ+gwOtySPzJNapbfS6hiZn2bKJafKjfSyH4Y51Dl6ZD/ldVob6o34zBw08W8x 2Li9dtxKoMuqsV8sP2GRGhayEmqCW+BudLPXqVlVcfmTR+WaaUl45fr22w/1ervSz/KL p/VimMdYm03JoSt4ZDFOtY9USkyfooBQ6YMpCJTMhDJRjUfSFUS1oh9J2Ir7OKSubxJn wuuxO7XkBNrZ7EILK+QTYbvR/fBotgzjdG6N1+kOHEy/tjE6tCNKk+meWPlb+l6OsoT3 FU4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752684081; x=1753288881; h=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=22lUn29S/TzuzXNANcDpHY5ZmO3RcDfXmK71AuEKaTU=; b=X+Vhbg4boLxVrCj40kiRyUHvz+pY5bo60zl0wadWJ2wgZ4iRXTol0V28QFHZesNRl0 UafTJ108cKuIW2ANE2QGufEhgxz0hxDfa3KSfKfLJR0ub53NNK6lFT7eRx//vAIBgg05 PzksJQlpTZRwC9MFS9vcLdVzc3FIkpDXCz2Qx+7GXduR7/YeIiW3Rh+9Q1jQ9ND35bhd uan1yNVKJSzycCwDMbtK44xi0hZ2XQZB85JQk71U+oZvbPqtzS1FZdu7iuycCkxdps6o nxD4pOmqYB+XLFkeSEQMI8r6R/lEI8j2TR5lNDEanreattLO4nwkgzp54UU0gX8oTPFa 2NVQ== X-Gm-Message-State: AOJu0YyQaxWGpYJkWCOqgmBkQEjA7Fc1KmvRX9Z1lnIon1GVzA3ffhvh hLy+yS//qfLjzcLdAdtrCc0MEvW1qjmAnYdwePmIcq9JVx9lnbned+Lzn/yLbFbUIC6SS+iwnRu xRbRVPWK9LPKw4YBZ4VejHVmdtUi7ThwF9qXU X-Gm-Gg: ASbGnctXhmlUWVAsKeD8mqfGUOJUyWv0UKdIOGAmTKrhmL0xiLDGVn4stvBLcmV3t// reKcyJQLW9TQjsVcEp7KnykZoDkYyLNDhD01wzaaiuF8g4wm3GdoxNiT3uCds5ae4o3aA9ydORs vu5pR8GU1kRFzRjV/yFrCoirp67ZStJd9iRoCPCDcDP7coRhK9js69BVhc8mOjq6GI62k2A7i7x Ale7k54lKUP0ly/Uk2KXGuEvO/Aw5NHjGpwEJU= X-Google-Smtp-Source: AGHT+IF81F+6Pepkvk2c6FevLaLukSPqkO0YVOLOdWun0eI29j9w70D7oDUgyLL1lApHMKE5nGINJE9GBF+vCpGhwkc= X-Received: by 2002:a05:6902:e8b:b0:e8b:499a:f657 with SMTP id 3f1490d57ef6-e8bc1d28f88mr2207033276.5.1752684080613; Wed, 16 Jul 2025 09:41:20 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: <1ecc1fd2-3837-4409-98c8-543b26de4955@app.fastmail.com> In-Reply-To: <1ecc1fd2-3837-4409-98c8-543b26de4955@app.fastmail.com> Date: Wed, 16 Jul 2025 13:40:44 -0300 X-Gm-Features: Ac12FXwReYHqcUWiN2Atlm7-JvcDsXsXDhh0KGFDwp0nRvo8NAgaCSV-V2SVEhQ Message-ID: Subject: Re: [PHP-DEV] Discussion Short Constructor To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="000000000000074cc4063a0e90fc" From: deleugyn@gmail.com (Deleu) --000000000000074cc4063a0e90fc Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Jul 16, 2025 at 12:59=E2=80=AFPM Larry Garfield wrote: > > I will reiterate what I have said many times in the context of function > autoloading: > > The only autoloader that really matters in practice is Composer. > > Composer supports "front-load this list of files". You can put whatever > you want in there. > > We have an opcache. I am really not concerned about the cost of > front-loading a bunch of small functions or classes. > > If you're using React, FrankenPHP, or many of the other new-wave run > models, you have a persistent process anyway so just expect everything to > get loaded. > > So having a "dto.php" or "classes.php" file that Composer just front-load= s > on every request that contains a bunch of one-liner class definitions (or > functions, or whatever) is perfectly fine, and works today. > > The only thing that would need to change is for SA tools (mostly PHPStorm= ) > to be less whiny if they see a class that doesn't match its file name. B= ut > I am quite confident JetBrains can figure out how to do that. > > In short: This is not a real problem. There's no need for us to make it > one. > > --Larry Garfield > This works for me, but if I do it alone on my projects, it's just an invitation for someone else to call it legacy garbate and undo it. Perhaps I'm alone in this bubble and everyone else is already doing it, but from where I'm standing that's just a recipe for people to raise their eyebrows and feel confused. For better or worse, Composer "files" feature is nearly as flexible as PHP autoloader. I could make what I want work with either of them, but if every project has a different approach on how to do it, we're slightly back to 2000's PHP or we're in 2020's Node. Maybe I brought this upon myself by mentioning Typescript's capabilities, but to be more precise, I do it (and love it) while working on Single File Components in VueJS, which is not a language-wide standard, but in its own corner it is a comprehensive and well established standard. Should I have a single `classes.php` on my Composer files and put everything in there? Should it be one file per module? If someone on my team copy/paste a file like that into another module/project/repository/whatever and suddenly they're seeing "PHP Error class not found" for 2 hours because this is such an uncommon error in modern PHP, is it his mistake for not understanding it or is it mine for creating something far away from obvious? The blessing and the curse of PSR-4 is that it spoiled us (or maybe just me?) to: - never think about `require/include` - never think about composer.json - never think about how classes/interfaces/traits are located - IDEs will auto-import stuff so I don't even need to think about `use` statement - I don't know how to debug "Class not found" issues because the last time I saw an error like this was 5 years ago when I was trying to mess up with custom autoload capabilities in order to declare multiple symbols in a single file. Maybe I'm alone in it and then it's fine for it to be just my problem. I'm sharing here in case it's also someone else's problem and we can do something about it. But please don't tell me it's not a real problem. --=20 Marco Deleu --000000000000074cc4063a0e90fc Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


On Wed, Jul 16,= 2025 at 12:59=E2=80=AFPM Larry Garfield <larry@garfieldtech.com> wrote:

I will reiterate what I have said many times in the context of function aut= oloading:

The only autoloader that really matters in practice is Composer.

Composer supports "front-load this list of files".=C2=A0 You can = put whatever you want in there.

We have an opcache.=C2=A0 I am really not concerned about the cost of front= -loading a bunch of small functions or classes.=C2=A0

If you're using React, FrankenPHP, or many of the other new-wave run mo= dels, you have a persistent process anyway so just expect everything to get= loaded.

So having a "dto.php" or "classes.php" file that Compos= er just front-loads on every request that contains a bunch of one-liner cla= ss definitions (or functions, or whatever) is perfectly fine, and works tod= ay.

The only thing that would need to change is for SA tools (mostly PHPStorm) = to be less whiny if they see a class that doesn't match its file name.= =C2=A0 But I am quite confident JetBrains can figure out how to do that.
In short: This is not a real problem.=C2=A0 There's no need for us to m= ake it one.

--Larry Garfield

This works for me, but= if I do it alone on my projects, it's just an invitation for someone e= lse to call it legacy garbate and undo it. Perhaps I'm alone in this bu= bble and everyone else is already doing it, but from where I'm standing= that's just a recipe for people to raise their eyebrows and feel confu= sed. For better or worse, Composer "files" feature is nearly as f= lexible as PHP autoloader. I could make what I want work with either of the= m, but if every project has a different approach on how to do it, we're= slightly back to 2000's PHP or we're in 2020's Node. Maybe I b= rought this upon myself by mentioning Typescript's capabilities, but to= be more precise, I do it (and love it) while working on Single File Compon= ents in VueJS, which is not a language-wide standard, but in its own corner= it is a comprehensive and well established standard.=C2=A0

<= /div>
Should I have a single `classes.php` on my Composer files and put= everything in there? Should it be one file per module? If someone on my te= am copy/paste a file like that into another module/project/repository/whate= ver and suddenly they're seeing "PHP Error class not found" f= or 2 hours because this is such an uncommon error in modern PHP, is it his = mistake for not understanding it or is it mine for creating something far a= way from obvious?

The blessing and the curse of PS= R-4 is that it spoiled us (or maybe just me?) to:
- never think about `r= equire/include`
- never think about composer.json
- nev= er think about how classes/interfaces/traits are located
- IDEs w= ill auto-import stuff so I don't even need to think about `use` stateme= nt
- I don't know how to debug "Class not found" is= sues because the last time I saw an error like this was 5 years ago when I = was trying to mess up with custom autoload capabilities in order to declare= multiple symbols in a single file.

Maybe I'm = alone in it and then it's fine for it to be just my problem. I'm sh= aring here in case it's also someone else's problem and we can do s= omething about it. But please don't tell me it's not a real problem= .

--
=
Marco Deleu
--000000000000074cc4063a0e90fc--