473,378 Members | 1,507 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

include 'filename.php' vs. exit 'whatever'

To quote from <http://php.net/function.include>,

"Because include() is a special language construct, parentheses are
not needed around its argument. Take care when comparing return
value."

exit is a language construct, also. To quote from <http://php.net/
function.exit>,

"this is a language construct"

So why does include 'whatever' work while exit 'whatever' doesn't? If
include doesn't require parenthesis because it's a language construct,
that implies that no language construct requires parenthesis, but...
if I don't use parenthesis with exit, I get a syntax error...
Jun 2 '08 #1
11 2424
On May 26, 10:51 pm, yawnmoth <terra1...@yahoo.comwrote:
To quote from <http://php.net/function.include>,

"Because include() is a special language construct, parentheses are
not needed around its argument. Take care when comparing return
value."

exit is a language construct, also. To quote from <http://php.net/
function.exit>,

"this is a language construct"

So why does include 'whatever' work while exit 'whatever' doesn't? If
include doesn't require parenthesis because it's a language construct,
that implies that no language construct requires parenthesis, but...
if I don't use parenthesis with exit, I get a syntax error...
You CAN use exit without parenthesis, using parenthesis allow you to
return an error code value. Note, using exit without passing an error
code is like passing exit(0).

If you are getting syntax error, could you please post the error...

From php.net code block examples:

Example #2 exit() status example
<?php

//exit program normally
exit;
exit();
exit(0);

//exit with an error code
exit(1);
exit(0376); //octal

?>
Jun 2 '08 #2
yawnmoth wrote:
To quote from <http://php.net/function.include>,

"Because include() is a special language construct, parentheses are
not needed around its argument. Take care when comparing return
value."

exit is a language construct, also. To quote from <http://php.net/
function.exit>,

"this is a language construct"

So why does include 'whatever' work while exit 'whatever' doesn't? If
include doesn't require parenthesis because it's a language construct,
that implies that no language construct requires parenthesis, but...
if I don't use parenthesis with exit, I get a syntax error...
Because that's the way the language is designed. exit() requires
parens, include doesn't.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jun 2 '08 #3
On May 27, 3:51 am, yawnmoth <terra1...@yahoo.comwrote:
To quote from <http://php.net/function.include>,

"Because include() is a special language construct, parentheses are
not needed around its argument. Take care when comparing return
value."

exit is a language construct, also. To quote from <http://php.net/
function.exit>,

"this is a language construct"

So why does include 'whatever' work while exit 'whatever' doesn't? If
include doesn't require parenthesis because it's a language construct,
that implies that no language construct requires parenthesis, but...
if I don't use parenthesis with exit, I get a syntax error...
The simple way around this problem is to just treat everything as if
it does require brackets. * always use brackets with return, die,
include etc and have never run into any problems.
Jun 2 '08 #4
On May 26, 11:05 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
yawnmoth wrote:
To quote from <http://php.net/function.include>,
"Because include() is a special language construct, parentheses are
not needed around its argument. Take care when comparing return
value."
exit is a language construct, also. To quote from <http://php.net/
function.exit>,
"this is a language construct"
So why does include 'whatever' work while exit 'whatever' doesn't? If
include doesn't require parenthesis because it's a language construct,
that implies that no language construct requires parenthesis, but...
if I don't use parenthesis with exit, I get a syntax error...

Because that's the way the language is designed. exit() requires
parens, include doesn't.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
Anyone else not get a syntax error on use of exit; (without braces)
PHP 5.2.3, no reported syntax error with E_ALL turned on.
Jun 2 '08 #5
ELINTPimp wrote:
On May 26, 10:51 pm, yawnmoth <terra1...@yahoo.comwrote:
>To quote from <http://php.net/function.include>,

"Because include() is a special language construct, parentheses are
not needed around its argument. Take care when comparing return
value."

exit is a language construct, also. To quote from <http://php.net/
function.exit>,

"this is a language construct"

So why does include 'whatever' work while exit 'whatever' doesn't? If
include doesn't require parenthesis because it's a language construct,
that implies that no language construct requires parenthesis, but...
if I don't use parenthesis with exit, I get a syntax error...

You CAN use exit without parenthesis, using parenthesis allow you to
return an error code value. Note, using exit without passing an error
code is like passing exit(0).

If you are getting syntax error, could you please post the error...

From php.net code block examples:

Example #2 exit() status example
<?php

//exit program normally
exit;
exit();
exit(0);

//exit with an error code
exit(1);
exit(0376); //octal

?>
I think what the op is saying is:

if both these are valid:
include 'test.php';
include('test.php');

then why aren't both these:
exit 1;
exit(1);

The former exit giving the parse error.

I just use parenthesis everywhere to avoid the issue.

Robin
Jun 2 '08 #6
On May 27, 7:44 am, Robin <a...@somewhere.comwrote:
ELINTPimp wrote:
On May 26, 10:51 pm, yawnmoth <terra1...@yahoo.comwrote:
To quote from <http://php.net/function.include>,
"Because include() is a special language construct, parentheses are
not needed around its argument. Take care when comparing return
value."
exit is a language construct, also. To quote from <http://php.net/
function.exit>,
"this is a language construct"
So why does include 'whatever' work while exit 'whatever' doesn't? If
include doesn't require parenthesis because it's a language construct,
that implies that no language construct requires parenthesis, but...
if I don't use parenthesis with exit, I get a syntax error...
You CAN use exit without parenthesis, using parenthesis allow you to
return an error code value. Note, using exit without passing an error
code is like passing exit(0).
If you are getting syntax error, could you please post the error...
From php.net code block examples:
Example #2 exit() status example
<?php
//exit program normally
exit;
exit();
exit(0);
//exit with an error code
exit(1);
exit(0376); //octal
?>

I think what the op is saying is:

if both these are valid:
include 'test.php';
include('test.php');

then why aren't both these:
exit 1;
exit(1);

The former exit giving the parse error.

I just use parenthesis everywhere to avoid the issue.

Robin
Ah, now I'm on the same page.
Jun 2 '08 #7
ELINTPimp wrote:
On May 26, 11:05 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
>yawnmoth wrote:
>>To quote from <http://php.net/function.include>,
"Because include() is a special language construct, parentheses are
not needed around its argument. Take care when comparing return
value."
exit is a language construct, also. To quote from <http://php.net/
function.exit>,
"this is a language construct"
So why does include 'whatever' work while exit 'whatever' doesn't? If
include doesn't require parenthesis because it's a language construct,
that implies that no language construct requires parenthesis, but...
if I don't use parenthesis with exit, I get a syntax error...
Because that's the way the language is designed. exit() requires
parens, include doesn't.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================

Anyone else not get a syntax error on use of exit; (without braces)
PHP 5.2.3, no reported syntax error with E_ALL turned on.
With just exit; no. But try to pass a return value, i.e. exit 4;

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jun 2 '08 #8
On Mon, 26 May 2008 23:05:11 -0400, Jerry Stuckle
<js*******@attglobal.netwrote in
<-p******************************@comcast.com>:
>yawnmoth wrote:
>To quote from <http://php.net/function.include>,

"Because include() is a special language construct, parentheses are
not needed around its argument. Take care when comparing return
value."

exit is a language construct, also. To quote from <http://php.net/
function.exit>,

"this is a language construct"

So why does include 'whatever' work while exit 'whatever' doesn't? If
include doesn't require parenthesis because it's a language construct,
that implies that no language construct requires parenthesis, but...
if I don't use parenthesis with exit, I get a syntax error...

Because that's the way the language is designed. exit() requires
parens, include doesn't.
And yes, it is inconsistent.
--
Charles Calvert | Software Design/Development
Celtic Wolf, Inc. | Project Management
http://www.celticwolf.com/ | Technical Writing
(703) 580-0210 | Research
Jun 2 '08 #9
Charles Calvert wrote:
On Mon, 26 May 2008 23:05:11 -0400, Jerry Stuckle
<js*******@attglobal.netwrote in
<-p******************************@comcast.com>:
>yawnmoth wrote:
>>To quote from <http://php.net/function.include>,

"Because include() is a special language construct, parentheses are
not needed around its argument. Take care when comparing return
value."

exit is a language construct, also. To quote from <http://php.net/
function.exit>,

"this is a language construct"

So why does include 'whatever' work while exit 'whatever' doesn't? If
include doesn't require parenthesis because it's a language construct,
that implies that no language construct requires parenthesis, but...
if I don't use parenthesis with exit, I get a syntax error...
Because that's the way the language is designed. exit() requires
parens, include doesn't.

And yes, it is inconsistent.
I'm not arguing whether it is inconsistent or not - but that's the way
it works.

I suspect it goes back to C/C++, where exit() is a function call, but
#include is a preprocessor direction. Of course, since PHP doesn't have
a preprocessor, it just uses include.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jun 2 '08 #10
On May 26, 10:51 pm, yawnmoth <terra1...@yahoo.comwrote:
So why does include 'whatever' work while exit 'whatever' doesn't? If
include doesn't require parenthesis because it's a language construct,
that implies that no language construct requires parenthesis, but...
if I don't use parenthesis with exit, I get a syntax error...
As Jerry Stuckle said, that is the way the language is designed. You
are drawing the wrong conclusion about what the phrase "langauge
construct" means. "language contructs" in PHP don't have to be
consistent with each other. PHP is notorious for its inconsistencies
(function names like str_replace and strpos remain embarrassments for
the language). When the documentation says "this is a language
construct" what they mean "this works in a wholly arbitrary manner,
defined here in the documentation".
Jun 2 '08 #11
lawrence k wrote:
On May 26, 10:51 pm, yawnmoth <terra1...@yahoo.comwrote:
>So why does include 'whatever' work while exit 'whatever' doesn't? If
include doesn't require parenthesis because it's a language construct,
that implies that no language construct requires parenthesis, but...
if I don't use parenthesis with exit, I get a syntax error...

As Jerry Stuckle said, that is the way the language is designed. You
are drawing the wrong conclusion about what the phrase "langauge
construct" means. "language contructs" in PHP don't have to be
consistent with each other. PHP is notorious for its inconsistencies
(function names like str_replace and strpos remain embarrassments for
the language). When the documentation says "this is a language
construct" what they mean "this works in a wholly arbitrary manner,
defined here in the documentation".
Why do you say "str_replace and strpos remain embarrassments for
the language"? I just had occasion to use str_replace yesterday and it
did exactly the job I wanted.
Jun 2 '08 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Kornelius Finkenbein | last post by:
Hello folks! I've got a strange problem with my download-script in conjunction with M$ internet explorer, if the filename I want to link to includes more than one points. In Netscape the problem...
5
by: David Leon | last post by:
Is there any way to stop php.exe closing after it processes a PHP script? It doesn't seem to have the traditional options of an MS-DOS program. I am using Windows XP Pro and have associated .php...
7
by: Paul Marshall | last post by:
Hi I am my wits end! I have a PHP script running that captures variables posted from a form on the previous page. The script then emails the results using the mail() function. The script is...
2
by: Robizzle | last post by:
I'm working on a very simple script that logs the ip address, time of hit, and os/browser information and currently it works every time. The problem is getting the script included into my html...
6
by: Puzzled | last post by:
This is a weird problem, but perhaps someone else has seen it before (I hope!) If I use a fully qualified include call include ( 'http://localhost/subtree/filename.php') I get an 'undefined...
12
by: TMN | last post by:
Hi All I am new to PHP and I do not understand why the following works ?? $file=urlencode("displayIncidents.php"); echo "<a href=statistics.php?fileName=$file&delete=true>Delete...
10
by: SoulIntruder | last post by:
Hello folks. I have a beginners question. I have such script: <?php $User = $_POST; $Password = $_POST; $Database = $_POST;
3
by: Tom | last post by:
Hi all i have problem with include function in my code after change php4 to php5. after standard html code i put in html body <? include ("filename.php"); ?> and close body and html. With php4...
1
by: chennaibala | last post by:
can any one send me mutiple image upload program and save the file name with extension in mysql table.we must cheak uploaded file type like bmp or any image file while uploading. i develop...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.