Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127877 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 BFA9A1A00BC for ; Fri, 4 Jul 2025 14:50:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1751640529; bh=DY0w1V9Ov9eHCplbm2AuYi/9YaIe0njPs75awVe7h2Q=; h=From:Date:Subject:To:From; b=JBzUBiK3Z7nkgDj6hO80YEExGb5fdqpEKmaj+QS0DGDq6cXs+QexF8UDkSmhfCI+Z +3VTCTYKXAESLusWq9rrtpgWpzpfv84vWHcAtmntopldhE5U6Q2UvgnsGlxEporZIH gvvhkjn3pKmUqEIcBWPxcxSlSRj+DL6vXw5lR3VolyxeEmbLNREsrDkC2BNWkc+aNI kMfUB19KGHrjc279Zj9NQW3L+EesBIIA/w9KeeUILGFpU7FaD8VvmIdpPoeGKZjQ83 u2ZwlezIEM9/2kp5nhXJDVdi+GTKuNsh0cK1817oGnNzY19kvI7g1pi4huwLrSkn1L BTJW7INFBGrgw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C53DD180057 for ; Fri, 4 Jul 2025 14:48:48 +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.2 required=5.0 tests=BAYES_40,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, 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-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) (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, 4 Jul 2025 14:48:45 +0000 (UTC) Received: by mail-pg1-f180.google.com with SMTP id 41be03b00d2f7-b2c2c762a89so808388a12.0 for ; Fri, 04 Jul 2025 07:50:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1751640636; x=1752245436; darn=lists.php.net; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=flikpMU3xhxNch1Dn6fSRkMzHJR5/A/4+CO2S417A0o=; b=ExAvLILy9Tg5EHMfAALLaAk8vrz6P/ve0L30DCsMyqXh+zgjzdZxt+Vxn6w1gFavsk /d32etdZ4lc0i00Zo4vYWGzx4xJsQbYthBGbpKBH9Pax1W6ssQCWyPjFpNXzuNdxXtqi a8K3pMsOL1fGCnhDKLfNcCuSf95Nq9aDGpL8cNzaLpDhUBycEkm1Mf0xTM7gC5X8FaGS QSz2rKaWIDQb97hbQIIR/ys6lG3gdpAxc2mEIuTCVX/XwDpbNTQdADI8boVrDeEWp5Jq xMwPC/GKg/UBoRd2g2Ewpby/RII0A+0GVQ0RoKi/yBR+fFrb1k/6TSphCOdBRNFfZERg G/aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751640636; x=1752245436; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=flikpMU3xhxNch1Dn6fSRkMzHJR5/A/4+CO2S417A0o=; b=fexf0H1UVbr5XsE4Kmc+mVOLFHT+/Gr+ZRpLntIR2rQoXrzjbgzJ+pf6q2TT3dPSba 4N3Akc82gDWzGYx+hAYwhzyS/v5rDEOihshtbv3sSgFDUtoM0ugT9s3sHsy5v+gbWNer RefuJVTldqxvRlVN7HqbIuje0yKmbqhBBlqxCp7X7My+Lt1Kcou/WYlvv889fplRMGJI 5RUN4Bg3/2mZHRMvHnj72pDMZ0FrvhEPEATFRfoHbVqnvTK//ZVMySDMLzFSVPImHNoU kj8eyShFoh6s8JJ8HclSEkLoOoqP1j/ZegeCNs01XhnIuNEs6gNXI3GD6xQJmDrr3h9O sITQ== X-Gm-Message-State: AOJu0YzD5HRNcOr5PEb8IJnUFVId+tGPb1Mo45fZSw8sB/ew7JEZEFDK xyiutrTlFj8gY7OlG2Hk/PMxAf2deCHi1RazD1kUWcrWWUwe6F6lYNwVTz4y4iQSYHKFmYnP3nO xGqhB/93ymSQZMmCC5u8NECF5nFJAVKYOFo/T73I= X-Gm-Gg: ASbGncu7D0UIsVlSLhseds4pSCJL5JQV5JMXiDPuPLTksnSfNDXoQrQIK+tGLRSWbcw ePeihoyeckfgId6oQ2wTswD1ZzJIiVBMgXy4XHdBj6+msG8aTqHcltcEIHsEXJ7p9JstgTQIBRF c2KGgfitVjQmPJy6V96e7aRphDNUQ1knQyoosRt2bUddzhWPbKyED61g== X-Google-Smtp-Source: AGHT+IGDb3+5u531EuRwX+PCha7DZ7rI1lMvDHK05V12D3pcROvp9AmQXR1tPrIUWE2x+iYcGdubcMCI59kZKrVPQJI= X-Received: by 2002:a17:90b:53ce:b0:311:c5d9:2c7c with SMTP id 98e67ed59e1d1-31aac53d29emr3863142a91.23.1751640636414; Fri, 04 Jul 2025 07:50:36 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Date: Fri, 4 Jul 2025 15:49:59 +0100 X-Gm-Features: Ac12FXyNPAC4gdP_z4wv5quCGz3wF7H7JOn5O3GZWJeotMsK-KHNbQ8ZPUObOBU Message-ID: Subject: [PHP-DEV] [RFC Idea] main() entry point for PHP To: PHP Developers Mailing List Content-Type: multipart/alternative; boundary="000000000000e85e4e06391b9d0a" From: fenniclog@gmail.com (fennic log) --000000000000e85e4e06391b9d0a Content-Type: text/plain; charset="UTF-8" This is basically an idea I have for PHP to support a main entry point. Where regardless of execution, if you run a PHP file, in CLI or Web request. If the file that is executed contains a main function, that is automatically executed by the engine after any procedural code. Any procedural code in the file, and included files are executed before main(). I made this decision because there would be cases where developers want to set up a global scope and variables. The main entry function MUST be within the executed file, any included files which contain a main function are treated as user functions. main function signature: `function main(): int;` main must return an int exit code. Example ```php echo "Before main"; function main(): int { echo "Executed in main"; return 0; } echo "After main"; return 1; // This is ignored as main() exists and its return value is the exit code. ``` Expected output: Before main After main Executed in main PHP returns code 0 *Open questions.* *1.* Should we add a declare(main_entry_point=true); for it to be opt-in *2.* Should main() take arguments? *3.* Should the main() be context aware? eg `main(array $argv, int $argc)` for the CLI SAPI. I'm not sure what it would be for CGI SAPI. --000000000000e85e4e06391b9d0a Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
This is basically an idea I have for PHP to support a main= entry point.
Where regardless of execution, if you run a PHP file, in = CLI or Web request.=C2=A0
If the file that is executed contains a= main function, that is automatically executed by the engine after any proc= edural=C2=A0code.=C2=A0

Any procedural code in the= file, and included files are executed before main(). I made this decision = because there would be cases where developers want to set up=C2=A0a global = scope and variables.
The main entry function MUST be within the e= xecuted file, any included files which contain a main function are treated = as user functions.

main function signature: `function main(): i= nt;` main must return an int exit code.

Example
```php
echo "Before main";
function main(): int
{
=C2=A0 =C2=A0 echo "Executed in main";
=C2=A0 =C2=A0 return 0;
}
echo "After main"= ;;
return 1; // This is ignored as main() exists and its return v= alue is the exit code.
```

Expected output:
= Before main
After main
Executed in main
PHP returns code 0<= /div>

Open questions.

1.=C2=A0Shoul= d we add a declare(main_entry_point=3Dtrue); for it to be opt-in
= 2. Should main() take arguments?
3. Should the main= () be context aware? eg `main(array $argv, int $argc)` for the CLI SAPI. I&= #39;m not=C2=A0sure what it would be for CGI SAPI.


--000000000000e85e4e06391b9d0a--