![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Oct 2005
Posts: 54
Rep Power: 4
![]() |
return_values PHP
I have trouble understanding the meaning of the return_var in PHP.
I read that it is used in order to inform us if a PHP command has been executed. I use system commands in PHP (like 'system', 'shell_exec' etc) and I can't find anywhere a list of the return_vars. I mean that 0 is for 'OK, the command was executed'. What does 1 stand for??? I execute a system command , I don't get any result, and if I ask PHP for the return_var, it says '1'. Where could I find more info as to what return_var=1 means? |
|
|
|
|
|
#2 |
|
Programming Guru
![]() |
It means that the program executed exited with a status of EXIT_FAILURE (1) and not EXIT_SUCCESS (0) and an error occurred. Generally anything above 0 means the program failed...
__________________
|
|
|
|
|
|
#3 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
It is, of course, purely convention. I can write a program that performs perfectly, and return the value 7,356. Nevertheless, I always return a 0 (EXIT_SUCCESS) for success and almost always 1 (EXIT_FAILURE) for anything else. While Tempest is absolutely correct, it isn't something one can bank on. I see jillions of things that return nothing. The executive usually replaces that nothing with something, but you can't know what it is, always. Check the documentation for the application, but be aware that someone who isn't doing it conventionally will probably not even address the question.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#4 |
|
Programmer
Join Date: Oct 2005
Posts: 54
Rep Power: 4
![]() |
Hi, thanx for your time.
My problem really has to do with WHAT the return values mean. My problem is that I call an external program through PHP, using system ('program', $return_value); I wanted to know if there is any kind of documentation saying perhaps that 'if you have $return_value=1, then it means that you have ... problem'. I hope I am clear to you. i want to figure out WHY the program hasn't been called from PHP, so as to fix the problem if I can (if it has to do with permissions or whatever).. |
|
|
|
|
|
#5 |
|
Programming Guru
![]() |
You are perfectly clear to us, but maybe we haven't been to you.
In a restatement of what DaWei said: The return value is not something that PHP knows the meaning of, it is set by the program you've executed at the end of processing... Please refer to the documentation for whatever program you are calling to determine what 0 (commonly EXIT_SUCCESS meaning a successful exit of the program) and 1 (commonly EXIT_FAILURE meaning a successful exit of the program) mean in terms of that particular 'program'...
__________________
|
|
|
|
|
|
#6 |
|
Expert Programmer
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 4
![]() |
damn... that means all my programs are written wrong
I always use 1 for success, 0 for failure.. seems most logical in my eyes, since 1 is often equal to true, and 0 to false. |
|
|
|
|
|
#7 | |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Quote:
MY PROGRAM SCREWED UP. One might reason that there is often one way for something to succeed and lebenty-jillion ways for it to fail. There's only one "zero". How are YOU going to allocate your indicative numbers?
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|