Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127882 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 3ED311A00BF for ; Fri, 4 Jul 2025 21:03:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1751662900; bh=KX2VAx7naUgsWUXx0xPBZda1yR7TgwbhNil/M3bpkdM=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=KSXsQ1oHcNsp+M7/8+4aR8LTVTaH59HtXWhBI7HNzQfMw73KpeXC9/NNEunGreE8S mv+ngZ/O7H1ptUU1SZT5MACOnK5vWK2ZtFaOLKAI8iTa6d0C9pp/1bYWapOKBWdVsU 2ddIJchHx+6bd7q7RJtPHGFsqykObCyktX1L4DFiiVWxXAFmPjXIXl3vUP14HF7AsQ IzaWipSEGXfsWL3YjStZPDpUPnwixpOZrdSj9gf5BD78NgvKCE7JRh3qkt9yvRFENv wU63zJOX/ftqREh0mzFZDyPZs6EIy4l+HozqWjtqQ/LCdeNQFZRbSYodWIImfHi54i WHakOELI0+ueQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 8D4F71801DB for ; Fri, 4 Jul 2025 21:01:37 +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-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) (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 21:01:33 +0000 (UTC) Received: by mail-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-60c4f796446so1854711a12.1 for ; Fri, 04 Jul 2025 14:03:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1751663004; x=1752267804; 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=4IwDLGfSjyz37uZ7NU82C9F68o/aphQqTte8Iz2ttRc=; b=I5UYfWRXGvgBSAPn5q56A1V3Hu9UEe49JsYaJ+YN8nBDQlKwvK/lGQUxXEIG4hIJCR XMsWUhnOl9XQQhHBj1xl9nSXeSYTAROV4PRBPV2XW3qYXDQjN5Ny84S58mspekA47Oi2 mv0hsjXNHdGbTWikaDnE1brfa03BZ01FSLkcK4Lfqt4nI4Y+X3dPPI3c2Rx9caC/CMe0 v1bXist9CtcLXcdBkff3+O3QD0gha9EGmxxqaZ00kkTT7ZTPSSXCIa6skRVAB03ekuIG OXSp8XsJ3a7oI/lcyiqgsppf7MjWPdF0ztvgmSi4TOnL/3xJg14afNAwj1SeKkJOFgTF J6tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751663004; x=1752267804; 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=4IwDLGfSjyz37uZ7NU82C9F68o/aphQqTte8Iz2ttRc=; b=AJtaephmuuh7jiMN0wPj27DAiBe7pmQ6bHQMMXc9ZtBn27hxj6s4Z8M7t9nA02YaCk A7r0nYMaWxh4Huc+FmIto6Pk37kNMmhBgg+cCGTrCgQ1rBePU1JcqLKRKr7gFFrzUB2e yFzeXGKumiWxw+W5KkHQIe0v/SkZm6XhaLC88TbE3EMrnksEzwDAMJOIfQkmZi3XYNLO B5WlerLehJRJ43VcZHMUAK6gIcj67K+fLYzLhxF5mw/wQXJkCyFe7+5YDZohlvLaOcVp PAOxZ5Y//+R7CQgFDNZ6zfgeykgcx7ZeIOUJ1/fG/T7aypmEihUm4hR7+28aAWi6poJE 0AVQ== X-Forwarded-Encrypted: i=1; AJvYcCWwDr6qt97d3cNDmQO4F3x4SDBd2Y26LthPpzK3qJjVNUNY1QJJ4QEft/7MKhg660fL169FhJkB+BY=@lists.php.net X-Gm-Message-State: AOJu0YzjVuLKYGBSUVsxdcoEYwtib/Q3I68mujOi+hYNO0L7NMKrQtZq ZUGHAePprCRmnUo33A5ryBdxzRPcfPpzdCYXge9/wHkktr+L73sxc2x8XJW3yGAOgjRl2mM7Ial VaCuPBkhJkkf3aXp0Tq2NV6p96onTdAw= X-Gm-Gg: ASbGnct0QEoHqhe4yi8KSWms09kA5yCreSaSLf4cw2d5KryUyHwRcodNbZBmeaNcY/s ej+gbuVyuVOemH6LIHBTJ+dsqXF+X4gFuYVnpSi3vbu8h9pkaQ16ykfDwKLhHDx7VSHcrFRnnlf WoaYNJFmL2y/l0gzrZ2I2Xmg2FUSXFIC/YUxBGbLOOYhQ= X-Google-Smtp-Source: AGHT+IHBRdjVon7iUiR/5Md5hq6qYC+fopEDSxrmgEHBHwh5KfQuKi4mYO9qaWVm27/wWAwWmM5JSDs1lT769HxgTrQ= X-Received: by 2002:a17:907:6ea4:b0:ae3:5e27:8e66 with SMTP id a640c23a62f3a-ae4107e045dmr6691366b.27.1751663002819; Fri, 04 Jul 2025 14:03:22 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: In-Reply-To: Date: Sat, 5 Jul 2025 00:03:11 +0300 X-Gm-Features: Ac12FXwvQhs5g1hvwUuDvvkvkGIfDfvbaE-9x1p4zXY22GHyZnfF6IWdvPyXvQg Message-ID: Subject: Re: [PHP-DEV] [RFC Idea] main() entry point for PHP To: Kamil Tekiela Cc: fennic log , PHP Developers Mailing List Content-Type: multipart/alternative; boundary="0000000000000ca081063920d36f" From: i.miroslavov@gmail.com (Iliya Miroslavov Iliev) --0000000000000ca081063920d36f Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Jul 4, 2025 at 6:09=E2=80=AFPM Kamil Tekiela = wrote: > > > On Fri, Jul 4, 2025, 16:50 fennic log wrote: > >> 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 develope= rs >> 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 th= e >> 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=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'm not sure what it would be for CGI SAPI. >> > > Why though? > > You are just saving seven keystrokes. > > main(); > > Besides, PHP already has main function so what you are proposing would be > confusing. > fennic, you don't get the concept of the `main` function. Nothing will be printed before nor after. Only what is inside it as a rule nothing else is executed outside that scope. You will end up with "headers already sent" and so on with that proposition. Kamil, you forgot to count the enter button for the new line... sheesh :) --=20 Iliya Miroslavov Iliev i.miroslavov@gmail.com --0000000000000ca081063920d36f Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


On Fri, Jul 4, = 2025 at 6:09=E2=80=AFPM Kamil Tekiela <tekiela246@gmail.com> wrote:


On Fri, Jul 4, 2025, 16:50 = fennic log <fen= niclog@gmail.com> wrote:
This is basically an idea I have for PHP t= o 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 exe= cuted contains a main function, that is automatically executed by the engin= e after any procedural=C2=A0code.=C2=A0

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

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

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

Expe= cted output:
Before main
After main
Executed in main
PHP= returns code 0

Open questions.

1= .=C2=A0Should we add a declare(main_entry_point=3Dtrue); for it to be o= pt-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=C2=A0sure what it would be for CGI SAPI.

Why though?

You are= just saving seven keystrokes.=C2=A0

main();

Bes= ides, PHP already has main function so what you are proposing would be conf= using.=C2=A0


fennic,= you don't get the concept of the `main` function. Nothing will be prin= ted before nor=C2=A0after. Only what is inside it as a rule nothing=C2=A0el= se is executed outside that scope. You will end up with "headers alrea= dy sent" and so on with that proposition.

Kamil, you forgot to = count the enter button for the new line... sheesh :)
=C2=A0
= --
Iliya Miroslavov Iliev
--0000000000000ca081063920d36f--