Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113815 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 48070 invoked from network); 27 Mar 2021 17:10:21 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 27 Mar 2021 17:10:21 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DBF651804E2 for ; Sat, 27 Mar 2021 10:06:54 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from wout3-smtp.messagingengine.com (wout3-smtp.messagingengine.com [64.147.123.19]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 27 Mar 2021 10:06:54 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 5D957153F for ; Sat, 27 Mar 2021 13:06:53 -0400 (EDT) Received: from imap8 ([10.202.2.58]) by compute4.internal (MEProxy); Sat, 27 Mar 2021 13:06:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=5Y3OGQ QEXvB60JuaiTNj8F2hTJe4ztDC80KXDG2RndU=; b=PtIuOKUttnDIT8y9ThnReD Efa9/ehhoYldLih5eTV7QZcfZs4f8Ayu47fSxxXZUchD1sL3o0V0fKJ6yLSw6REe 69P31wg8Uqy7biaWNb2GZKLq4LCv9Mpef5V1cHP1mLeBOS/r/omKu9tlkmeT7EpO 6D71tZnbF3q3lb+j9AAvz7znKM+xPHxxUTI0SMcYM2XtnyAe7MwWi56uqmJeSDgM aJC7fsT46ETa6DeUk3KMA9YESOv4MkhCtxawZ3zaaKm2bcVm7Mdj2pQsquih+p7S k5gLk6hD3+0a0hDIfWcHoCp2/uNJXu5yimhwBclOLEygDrvSv5jXoOIor2kpxSxQ == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrudehgedgleeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgesthdtredtreertdenucfhrhhomhepfdfnrghr rhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtoh hmqeenucggtffrrghtthgvrhhnpeevheehvdevjeelvdevgfelvefftdejkeelvdekgeeh fffgiedvjefhhfeltdduteenucffohhmrghinhepphhhphdrnhgvthenucevlhhushhtvg hrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehlrghrrhihsehgrghrfhhi vghlughtvggthhdrtghomh X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id B6E2A3A0958; Sat, 27 Mar 2021 13:06:52 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.5.0-alpha0-273-g8500d2492d-fm-20210323.002-g8500d249 Mime-Version: 1.0 Message-ID: In-Reply-To: References: Date: Sat, 27 Mar 2021 12:06:32 -0500 To: "php internals" Content-Type: text/plain Subject: Re: [PHP-DEV] include vendor/autoload.php automatically From: larry@garfieldtech.com ("Larry Garfield") On Sat, Mar 27, 2021, at 11:52 AM, Abdul Haq Sheikh wrote: > If we want to use composer packages, we have to include > 'vendor/autoload.php', and if we don't have a front controller design > pattern, we must include 'vendor/autoload.php' on every/most files. Why not > to auto include 'vendor/autoload.php' file (if vendor folder exists)? > * PHP will use include_once to include file > > Example Directory Structure: > - Index.php (file) > - Test.php (file) > - Classes (folder) > -- Classes/test2.php (file) > - Vendor (folder) > > - On Index.php, php will automatically include 'vendor/autoload.php' > because the vendor directory exists. > - On Test.php, php will automatically include 'vendor/autoload.php' > because the vendor directory exists. > - On Classes/test2.php, since file is in sub directory and here vendor > directory doesn't exist, so php will not include 'vendor/autoload.php' vendor/autoload.php is a Composer-specific convention. It's not something imposed by PHP itself. It's also quite simple to auto-include a file on every request, using the auto_append_file ini directive: https://www.php.net/manual/en/ini.core.php#ini.auto-prepend-file If you don't have one or a small number of front controllers, that's a good setting to look into for exactly this purpose. --Larry Garfield