In php, the exit (0) method is used to declare the exit status (successful exit or unexpected termination due to some circumstances). What are the advantages of this method? What is the difference between this and direct exit?

Source: Internet
Author: User
Just like what is the difference between the following code {code...} and {code? Humbly ask the experts for advice, just like
The following code

Echo 'configuration error'; exit (3); // Status 3 indicates exit due to configuration error

And

// Exit directly ('configuration error ');

What is the difference?

I would like to ask you a question or two.

Reply content:

Just like
The following code

Echo 'configuration error'; exit (3); // Status 3 indicates exit due to configuration error

And

// Exit directly ('configuration error ');

What is the difference?

I would like to ask you a question or two.

First, let's draw a conclusion: there are slight differences.

Let's talk about the truth in the document:

If status is a string, this function prints the status just before exiting.

If status is an integer, that value will be used as the exit status and not printed. exit statuses shoshould be in the range 0 to 254, the exit status 255 is reserved by PHP and shall not be used. the status 0 is used to terminate the program successfully.
Note: PHP> = 4.2.0 does NOT print the status if it is an integer.

Simply put, if it is a string, it will be printed. if it is a number, it will be usedExit status code, Will not be printed.


  

Execute the above two lines of code separately. Obviously, the results are the same.

The difference is:
Comment out the second line and execute the following command on the terminal:
Php test. php // Print "error"
Echo $? //Print 3

Comment out the first line. run the following command on the terminal:
Php test. php // Print "error"
Echo $? //Print 0

That is to say, when the value of eixt () is int type, it is used as the exit status code.
$? Explanation: Stores the exit value of the last command that was executed (exit status of the last command, 0 indicates no error ).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.