Optional parenthesis on function calls in PHP

I’m learning PHP, and I accidentally forgot the parenthesis in Echo 'Example'

I’m curious as to why this worked, the only time I’ve seen this allowed was in SML, where the reason was that “All functions take only one item as a parameter, and that can be a tuple (A grouping of values)”

Is it similar to that reason? Or some other reason? I’m mostly interested for the sake of knowing if it conveys something more about the language… or if it is as simple as “Single argument functions do not need parenthesis”

I’m going to test what func1 func2 func3 "test argument" will do next… or even if it is possible! Any input on the order it will take would be a added pleasure.


As a general rule, whenever you are not sure about a PHP functionality, check the official documentation.

Specific to your question, the official documentation is here

Exactly as it was correctly pointed out by one of the commentators and as it says in the documentation:

echo is not actually a function (it is a language construct), so you are not required to use parentheses with it.

Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *