|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #81058 Inedible syntax porridge
Submitted: 2021-05-20 10:24 UTC Modified: 2021-05-20 10:42 UTC
From: zmfw1991 at gmail dot com Assigned:
Status: Not a bug Package: Compile Warning
PHP Version: Irrelevant OS: all?
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: zmfw1991 at gmail dot com
New email:
PHP Version: OS:


 [2021-05-20 10:24 UTC] zmfw1991 at gmail dot com
Semicolon after Control Structures.

Versions: php8.0.3, maybe php 5.3 and <5

Test script:

$arr = ['a', 'b', 'c', 'd'];


        example 1

echo "<h1>example 1:</h1>\r\n";

foreach ( $arr as $val );   // Semicolon after foreach! Errors not found!
    echo $val . "<br>\r\n";

        example 2

echo "<h1>example 2:</h1>\r\n";

function nope() {}

foreach ( $arr as $val);


    echo $val . "<br>\r\n";

        example 3

echo "<h1>example 3:</h1>\r\n";

if ( false );
    echo 'true';




    Because <i>foreach</i> and <i>if</i> is Control Structures?<br>\r\n

    These errors can be searched forever and never found. They are invisible.




Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-05-20 10:42 UTC]
-Status: Open +Status: Not a bug
 [2021-05-20 10:42 UTC]
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

 [2021-05-20 11:02 UTC] zmfw1991 at gmail dot com
No. This is bug!


Правильнее было бы определять это как синтаксическую ошибку и выдавать предупреждение, но php сейчас это не обнаруживает, он не замечает лишнюю точку с запятой после if () но перед {}. Здесь возможно неявное и непредсказуемое поведение, притом что врядли кто-то будет писать и ожидать корректного поведения от странных конструкции таких как: if( expression ); { code }

При этом PHP волне обнаруживает синтаксическую ошибку здесь, на слове else:

if ( false );
    echo 'true';
    echo 'true';

Но если else не указан, то PHP промолчит. Я на поиск такой ошибки убил час, а PHP молчит как партизан, она очень незаметна и не бросается в глаза, но это ошибка всё же.
 [2021-05-20 11:04 UTC] rtrtrtrtrt at dfdfdfdf dot dfd
garbage in - garbage out
 [2021-05-20 11:19 UTC] zmfw1991 at gmail dot com
It would be wiser to throw out ParseError. But php doesn't do that.
 [2021-05-20 11:20 UTC] rtrtrtrtrt at dfdfdfdf dot dfd
guess what: it's parseable
 [2021-05-20 22:17 UTC] a at b dot c dot de
You've discovered the concept of an empty loop (a loop "foreach()" containing an empty statement ";").

Empty statements are cromulent; they're allowed so one also has to allow loops to contain them. Empty loops have their uses.

There is no PHP bug here, only a typo in coding.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Mon Dec 04 14:01:28 2023 UTC