Doc #52722 [Com]: Don't teach beginners wrong stuff: Drop brackets around language constructs!
| From: | + at ni-po dot com | Date: | Mon, 20 Sep 2010 13:24:08 +0000 |
| Subject: | Doc #52722 [Com]: Don't teach beginners wrong stuff: Drop brackets around language constructs! | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-5090@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=52722&edit=1
ID: 52722
Comment by: + at ni-po dot com
Reported by: + at ni-po dot com
Summary: Don't teach beginners wrong stuff: Drop brackets
around language constructs!
Status: Bogus
Type: Documentation Problem
Package: Documentation problem
PHP Version: Irrelevant
Block user comment: N
New Comment:
@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.
Previous Comments:
------------------------------------------------------------------------
[2010-09-20 11:54:08] rquadling@php.net
There is nothing wrong with ...
if (include('file.php') == true)
when file.php returns true or false upon inclusion.
Perfectly valid.
------------------------------------------------------------------------
[2010-09-19 18:54:25] + 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-19 16:13:04] markskilbeck@php.net
How is it *wrong* to use parentheses with language-constructs? I don't
see that it is.
------------------------------------------------------------------------
[2010-08-28 14:15:35] + 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-08-28 14:10:53] + at ni-po dot com
Description:
------------
One thing that very much annoys me about the PHP documentation that it
teaches beginners *wrong* stuff by writing all language constructs with
parenthesis.
Example:
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.)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=52722&edit=1