Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the purpose of separate curly brackets in PHP [duplicate]

Tags:

php

Is it a parser bug, or is there any usefulness in using curly brackets like this?

$x = 1;

{
    $x++;
}

As far as I can see, it behaves exactly as if the brackets weren't there, so why is it valid syntax?

like image 764
Edson Medina Avatar asked Jan 07 '23 13:01

Edson Medina


1 Answers

There is no any hidden meaning. It is more about readability.

Check manual:

Any PHP script is built out of a series of statements. A statement can be an assignment, a function call, a loop, a conditional statement or even a statement that does nothing (an empty statement). Statements usually end with a semicolon. In addition, statements can be grouped into a statement-group by encapsulating a group of statements with curly braces. A statement-group is a statement by itself as well.

like image 161
Pawel Gumiela Avatar answered Jan 16 '23 22:01

Pawel Gumiela