FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » return value?
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: return value? [message #170893 is a reply to message #170887] Sun, 05 December 2010 18:11 Go to previous message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma:
Senior Member
Please do _not_ top-post; reply below *trimmed* quotations instead.

Paul Fredlein wrote:

> Thomas 'PointedEars' Lahn <PointedEars(at)web(dot)de> wrote:
>> Paul Fredlein wrote:
>>> $value = "0";
>>> return $value;
>>>
>>> I assume that would return a string (or in this case one char with the
>>> hex value of 30) - is that right?
>>>
>>> $value = 0;
>>> return $value;
>>>
>>> What does this return? Is it a string, a short int (little endian or
>>> big endian) or what?
>>
>> Yes and yes. (Try the gettype() function, or var_dump()).
>
> I'm returning the variables to a C++ programme running on the client
> machine, I'm just a bit confused with php.
>
> If I return "1234" then I'm returning a string of 4 chars - 4 bytes, but
> if it's a short int then it's only 2 bytes. Seems wasteful to return
> more than I need to do.

It is not clear how you are using this PHP script. AFAIK PHP scripts cannot
`return' a value; functions and includes (parts of PHP scripts) can `return'
a value, but that needs to be used by a PHP script [lower-stacked code, with
includes an (include|require)(_once)? statement.] Meaning that

php -r 'return 1;'

alone causes no syntax error here, but also outputs nothing and its exit
status is still 0 (zero).

If you are using what PHP sends to the standard output or standard error
stream, then what is printed is regarded a string of characters by C++
regardless of its PHP type, and you need to do a conversion from that string
of characters to an appropriate integer type in your C++ program.

If you are instead concerned about the exit status of a PHP script as
defined e.g. by an exit(…) function call, it will be of the type that the
platform uses that the PHP executable was compiled for, which should to be
the same as for your standard C++ library, since you could only get that
exit status directly if PHP and your C++ program were running on the same
machine.


PointedEars
--
Danny Goodman's books are out of date and teach practices that are
positively harmful for cross-browser scripting.
-- Richard Cornford, cljs, <cife6q$253$1$8300dec7(at)news(dot)demon(dot)co(dot)uk> (2004)
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: what better book ?
Next Topic: PHP/AJAX Problem
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Nov 22 21:17:02 GMT 2024

Total time taken to generate the page: 0.06380 seconds