Jump to content
Larry Ullman's Book Forums

Larry, Why Do You Use Exit() Instead Of Just Exit?


Recommended Posts

EDIT---

 

I meant to ask about difference between exit() and exit in this thread. I got mixed up with "quit" due to lack of sleep and confusing two different languages php and autoIT3....

 

Answer: there are three versions of the exit function... exit, exit() and exit('some message') all three do samething but the last example allows you to send a message. More info available about this at php.net.

 

for some reason exit() doesn't work for me that well at least not on php 5.2 but exit; does so if you have issues with the exit command as written in the book try WITH OUT the () and just put exit; it does the samething.

 

 

----

 

 

Hi,

 

I noticed in your book that you use

quit();

to exit the program. This NEVER works for me, I get errors actually in php when I use that, but

quit;

works fine.

 

Also when you move up a folder you use

a single ./ instead of ../

why is this?

 

I am just curious, because for me those two things as written in the book don't work for me at all, I have to alter using

 

quit;

AND

../

 

Maybe it is just my host but your versions don't work for me and was curious why you use those and what host you use that those work for you?

 

 

Thanks.

Link to comment
Share on other sites

I noticed in your book that you use

quit();

to exit the program. This NEVER works for me, I get errors actually in php when I use that, but

quit;

works fine.

 

To exit what program? Because I don't think quit() exists as a function in PHP.

 

Also when you move up a folder you use

a single ./ instead of ../

why is this?

 

Yeah...no. To move up a folder, I use ../

./ moves into a folder, starting from the current directory. These are not equivalent.

 

I am just curious, because for me those two things as written in the book don't work for me at all.

 

If you can provide specific pages where you're seeing these things and are confused, I can help explain what's going on.

 

Link to comment
Share on other sites

 quit(); 

 

I think what happened is you intended to type exit(); instead of quit(); There a few places I found this "typo" but one is:

 

 

Chapter 4 page 80.

At the end of redirect line just in case the redirect doesn't work php won't keep on processing the file and display content on the page that shouldn't be shown. I do this too.

 

 

You use exit() a lot in the book, I looked it up at php.net and it says this is used to display a message before stopping process of the file. Though in most the cases I see you using this there is no message so in these cases wouldn't it be better to use quit; ?

 

Besides the message thing, what benefits are there to using exit() vs quit or is it just personal preference?

 

 

I also found a typo on page 87 in section 9 you have create_password_hash($p) where it should be get_password_hash($p).

Link to comment
Share on other sites

./ moves into a folder, starting from the current directory. These are not equivalent.

 

Oh. I did not know that and have never used it before. Instead what I do is something like:

 

include('/subfolder1/subfolder2/');

 

This goes down two folders by name from the current file that is being called from. I didn't know I should add a period there at the beginning because it works, I maybe doing it wrong and never knew it.

Link to comment
Share on other sites

I think what happened is you intended to type exit(); instead of quit(); There a few places I found this "typo" but one is:

 

Chapter 4 page 80.

At the end of redirect line just in case the redirect doesn't work php won't keep on processing the file and display content on the page that shouldn't be shown. I do this too.

 

What version of the book are you using? I'm looking at Chapter 4, page 80, of the very first printing of the physical book, US, English language, and there's no use of quit() at all.

 

You use exit() a lot in the book, I looked it up at php.net and it says this is used to display a message before stopping process of the file. Though in most the cases I see you using this there is no message so in these cases wouldn't it be better to use quit; ? Besides the message thing, what benefits are there to using exit() vs quit or is it just personal preference?

 

Again, as far as I know, and if I'm wrong, please provide some documentation, but there is no "quit" in PHP. As for exit(), I almost never use it with a provided message.

 

I also found a typo on page 87 in section 9 you have create_password_hash($p) where it should be get_password_hash($p).

 

 

Yeah, I believe that's already on the errata page. That's what I get for changing the name of a function during the rewrites!

 

Oh. I did not know that and have never used it before. Instead what I do is something like:

 

include('/subfolder1/subfolder2/');

 

This goes down two folders by name from the current file that is being called from. I didn't know I should add a period there at the beginning because it works, I maybe doing it wrong and never knew it.

 

No, that does not go down two folders. It may have that effect, but that's not what the code is doing. What you have is an absolute reference, which is anything that starts with / or C:\ or http:// or the like. The initial X says "start with the root and go from there". Conversely, any reference that begins with a period, or two periods, or a file name or a folder name--in other words, any reference that doesn't begin with an absolute starting point, is a relative reference, relative to the current script.

 

This can be confusing stuff, I know.

 

 

Oh, and big thanks for helping out in answering some of the other people's questions. I really, really appreciate it!

 

 

Link to comment
Share on other sites

Hmmm... I swear I saw quit(); in the book... I tried quit; and it worked.. Hmmm.. Time for medication maybe.. LOL

 

I have never seen exit used with the () I looked it up at php.net and there are exit; exit(); and exit('some text here');

Three different ways of stopping script execution.

 

I also did not see quit over at php.net. I have been coding a lot in AutoIT v3 which does use quit... I looked at my code in 3 of my php projects and I have used exit;

LOL. Only thing I can say is I have coders hang over or something, seeing quit everywhere. LOL

 

 

Ok, starting a path with " / " tells php to start at the web root and work forward from there? So if I am in a file 3 folders down and I want to include a file in the web root folder I just do

 

include('/name_of_file.php');

 

 

I just noticed you said root... Ok, explain what root is. This is what I think it is, tell me if I am wrong.

 

Most people do not have access to root so it would be the root of their account which would be:

 

/home/username <---  THIS_IS_ROOT_FOLDER

 

So...

 

/home/username/public_html   <-- THIS IS WEB ROOT, BASE_URI, Document Root

 

Or whatever this folder is named which is the web accessible root folder, might not be public_html, could be www or something else.

 

 

So if I am 3 levels deep off of the web root and I want to access a file in web root folder via absolute reference:

 

include('/public_html/name_of_file.php');

 

 

 

You may want to check what exactly I am telling people cause I could be totally wrong. LOL

Anyway, I am here to learn and helping out when I can, helps me learn too. Though, I may not be correct. LOL

 

 

 

Thanks.

Link to comment
Share on other sites

If it makes you feel any better, quit is the command to use to exit the MySQL client (sometimes referred to as the MySQL monitor).

 

Root means different things in different contexts. When you are using include() or require(), PHP is looking at the file system it is running on (i.e., the root of the volume PHP is installed on). When you are referring to a web address, root means the folder that is designated as the document root. So when using include, the root is actually the first slash, not the path to the user's home directory. When I need to include a file relative to the current document, I use:

include ($_SERVER['DOCUMENT_ROOT'] . '/path/to/file');

This makes it easy to figure out the correct path, since you will be able to provide a full path, and also makes your code more portable between your dev site and production site when the directory structure is different.

Link to comment
Share on other sites

Actually I realize now what I was meaning to say with this thread.... I did not mean QUIT I mean EXIT.. I program several languages and recently have been using AutoIT3 which is a basic like language I use to create windows applications, mainly little tools I create to help me do things easier.

 

What I meant to say was what is the different between exit() and exit because exit() didn't seem to work well for me for some reason... Geez...

Anyway through research I figured out what the various methods of calling exit are and how they work...

 

(sigh). I am usually operating on too many hours of sleep loss, over worked and sometimes it catches up to me.

Link to comment
Share on other sites

There's no difference between exit and exit(), but exit is a language construct, not a function (I believe), which means the parentheses are not required. So, since they aren't required, I tend not to use them. The exception would be when providing a terminating message with exit, in which case you must use the parentheses.

Link to comment
Share on other sites

 Share

×
×
  • Create New...