Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is Exit(integer) and how to make use of it in PHP

I know nothing about C, C++ or any lower level than PHP. I take a glance into Codeigniter 3 codes at github and found it's added exit status code constants, i.e we can do:

exit(EXIT_DATABASE) means exit(8) or exit(EXIT_UNKNOWN_CLASS) means exit(5)

what is differ between

echo 'Configuration file not found';
exit(3);

and just

exit('Configuration file not found'); ?

What is the purpose of using exit(integer) in php ? it doesn't print anything, does it? I also check the docs and google some but still not get it clear. How to make use of this? where i can get reference about this ?

Thanks.

like image 540
egig Avatar asked Jun 07 '13 14:06

egig


1 Answers

It gives the caller a hint as to what the outcome of running your script is.

This can be useful in php if you are running a script with exec or system and you need to behave differently based on the outcome of running the script.

<?php
   $output = array();
   $error = null;
   exec("/path/to/php cleanData.php", $output, $error);
   if ($error){
       Logger::log($error, $output);
       die("Sorry I was Unable to Clean the Data\n");
   }
like image 142
Orangepill Avatar answered Sep 21 '22 13:09

Orangepill