|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #52722 Don't teach beginners wrong stuff: Drop brackets around language constructs!
Submitted: 2010-08-28 14:10 UTC Modified: 2010-09-20 11:54 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: + at ni-po dot com Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2010-08-28 14:10 UTC] + at ni-po dot com
One thing that very much annoys me about the PHP documentation that it teaches beginners *wrong* stuff by writing all language constructs with parenthesis.

If called from within a function, the return() statement immediately ends execution of the current function [...]

And it's like this everywhere!

Admittedly all code examples use the correct syntax without parentheses. But writing return() everywhere else in the documentation makes it seem like the parentheses belong to the return statement and the syntax without parenthesis is only another way to write it.

Thus I would strongly support the removal of this misleading notation. (This obviously doesn't apply only to the return statement, but to echo, print, include, include_once, require and require_once, too.)


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-08-28 14:15 UTC] + at ni-po dot com
Actually the documentation already uses a notation without parenthesis for two language constructs: break and continue are written without parenthesis.
 [2010-09-19 16:13 UTC]
-Status: Open +Status: Bogus
 [2010-09-19 16:13 UTC]
How is it *wrong* to use parentheses with language-constructs? I don't see that it is.
 [2010-09-19 18:54 UTC] + at ni-po dot com
@markskillbeck: If I wrote
#define min(X, Y) X < Y ? X : Y
in C instead of
#define min(X, Y) ((X) < (Y) ? (X) : (Y))
would you say it was wrong? I would. It may be syntactically correct, it may compile, but it doesn't make it correct.

It's same with the parenthesis in PHP. Writing
if (include('file.php') == true)
is correct syntax, but it is logically wrong. The parenthesis create the feeling of a function.
 [2010-09-20 11:54 UTC]
There is nothing wrong with ...

if (include('file.php') == true)

when file.php returns true or false upon inclusion.

Perfectly valid.
 [2010-09-20 15:24 UTC] + at ni-po dot com
@rquadling: See, that's exactly the problem. Even a senior PHP developer will be tricked into thinking that the return value of the include is compared. But PHP evaluated this as:
if (include ('file.php' == true))

This clearly shows that it's no good to write language constructs with parenthesis in the manual.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Aug 01 15:01:24 2021 UTC