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
Switch to threaded view of this topic Create a new topic Submit Reply
return value? [message #170864] Sat, 04 December 2010 07:39 Go to next message
paulfredlein is currently offline  paulfredlein
Messages: 8
Registered: December 2010
Karma: 0
Junior Member
Hi,

Basic newbie question:-

$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?

Thanks,

Paul
Re: return value? [message #170867 is a reply to message #170864] Sat, 04 December 2010 10:13 Go to previous messageGo to next message
Luuk is currently offline  Luuk
Messages: 329
Registered: September 2010
Karma: 0
Senior Member
On 04-12-10 08:39, Paul Fredlein wrote:
> Hi,
>
> Basic newbie question:-
>
> $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?

Yes, the answer is here:
http://www.php.net/manual/en/function.gettype.php

>
> $value = 0;
> return $value;
>
> What does this return? Is it a string, a short int (little endian or big
> endian) or what?

it should not be a string,
i should test this to see what happens,
before i know the answer
but so can you ;-)

>
> Thanks,
>
> Paul




--
Luuk
Re: return value? [message #170875 is a reply to message #170864] Sat, 04 December 2010 13:57 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 12/4/2010 2:39 AM, Paul Fredlein wrote:
> Hi,
>
> Basic newbie question:-
>
> $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?
>

It returns a string.

> $value = 0;
> return $value;
>
> What does this return? Is it a string, a short int (little endian or big
> endian) or what?
>

It returns an integer. little endian or big endian is hardware
dependent (and completely immaterial).

> Thanks,
>
> Paul


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: return value? [message #170878 is a reply to message #170864] Sat, 04 December 2010 17:31 Go to previous messageGo to next message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
Senior Member
Paul Fredlein wrote:

> Basic newbie question:-
>
> $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()).


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)
Re: return value? [message #170887 is a reply to message #170878] Sun, 05 December 2010 14:00 Go to previous messageGo to next message
paulfredlein is currently offline  paulfredlein
Messages: 8
Registered: December 2010
Karma: 0
Junior Member
Hi,

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.

Thanks,

Paul


Thomas 'PointedEars' Lahn <PointedEars(at)web(dot)de> wrote:

> Paul Fredlein wrote:
>
>> Basic newbie question:-
>>
>> $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()).
>
>
> PointedEars
Re: return value? [message #170888 is a reply to message #170887] Sun, 05 December 2010 14:13 Go to previous messageGo to next message
Luuk is currently offline  Luuk
Messages: 329
Registered: September 2010
Karma: 0
Senior Member
On 05-12-10 15:00, Paul Fredlein wrote:
> Hi,
>
> 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.
>
> Thanks,
>
> Paul
>

you also can convert this 1234 to hexadecimal,
than you would have 3 bytes ('4D2') to return,

Which seems to be the best of both world....

;-)

--
Luuk
Re: return value? [message #170889 is a reply to message #170887] Sun, 05 December 2010 14:48 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 12/5/2010 9:00 AM, Paul Fredlein wrote:
> Thomas 'PointedEars' Lahn<PointedEars(at)web(dot)de> wrote:
>
>> Paul Fredlein wrote:
>>
>>> Basic newbie question:-
>>>
>>> $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()).
>>
>>
>> PointedEars

<Top posting fixed>

> Hi,
>
> 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.
>
> Thanks,
>
> Paul
>
>
<top posting fixed>

You're worried about 2 bytes on a machine which has hundreds of
megabytes (or even gigabytes)?

If you're that worried about performance, you shouldn't be using PHP in
the first place. You should be doing everything in C. Or

Quite frankly, I've never seen anyone so obsessed with premature
optimization as you are, Paul. The things you're considering
"important" are so small in the scheme of things that they will be
unnoticeable.

And please don't top post.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: return value? [message #170892 is a reply to message #170888] Sun, 05 December 2010 18:01 Go to previous messageGo to next message
Allodoxaphobia is currently offline  Allodoxaphobia
Messages: 21
Registered: September 2010
Karma: 0
Junior Member
On Sun, 05 Dec 2010 15:13:42 +0100, Luuk wrote:
> On 05-12-10 15:00, Paul Fredlein wrote:
>>
>> 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.
>>
>> Thanks,
>>
>> Paul
>>
>
> you also can convert this 1234 to hexadecimal,
> than you would have 3 bytes ('4D2') to return,
>
> Which seems to be the best of both world....

Or, convert to raw binary and return it in 1 1/2 bytes. :-)
Re: return value? [message #170893 is a reply to message #170887] Sun, 05 December 2010 18:11 Go to previous messageGo to next message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
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)
Re: return value? [message #170897 is a reply to message #170889] Mon, 06 December 2010 07:58 Go to previous message
paulfredlein is currently offline  paulfredlein
Messages: 8
Registered: December 2010
Karma: 0
Junior Member
Hi,

I grew up in DOS where every byte counts.

It's not the capacity of the client, it's the data travelling through
the 'ether'.

I'll just return everything as strings and extract it as needed.

Thanks

Paul


Jerry Stuckle <jstucklex(at)attglobal(dot)net> wrote:

> On 12/5/2010 9:00 AM, Paul Fredlein wrote:
>> Thomas 'PointedEars' Lahn<PointedEars(at)web(dot)de> wrote:
>>
>>> Paul Fredlein wrote:
>>>
>>>> Basic newbie question:-
>>>>
>>>> $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()).
>>>
>>>
>>> PointedEars
>
> <Top posting fixed>
>
>> Hi,
>>
>> 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.
>>
>> Thanks,
>>
>> Paul
>>
>>
> <top posting fixed>
>
> You're worried about 2 bytes on a machine which has hundreds of
> megabytes (or even gigabytes)?
>
> If you're that worried about performance, you shouldn't be using PHP in
> the first place. You should be doing everything in C. Or
>
> Quite frankly, I've never seen anyone so obsessed with premature
> optimization as you are, Paul. The things you're considering
> "important" are so small in the scheme of things that they will be
> unnoticeable.
>
> And please don't top post.
Re: return value? [message #170899 is a reply to message #170892] Mon, 06 December 2010 07:58 Go to previous message
paulfredlein is currently offline  paulfredlein
Messages: 8
Registered: December 2010
Karma: 0
Junior Member
Hi,

Even better, I'll return it as 'one, two, three, four' then it's
properly human readable.

Thanks,

Paul


Allodoxaphobia <knock_yourself_out(at)example(dot)net> wrote:

> On Sun, 05 Dec 2010 15:13:42 +0100, Luuk wrote:
>> On 05-12-10 15:00, Paul Fredlein wrote:
>>>
>>> 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.
>>>
>>> Thanks,
>>>
>>> Paul
>>>
>>
>> you also can convert this 1234 to hexadecimal,
>> than you would have 3 bytes ('4D2') to return,
>>
>> Which seems to be the best of both world....
>
> Or, convert to raw binary and return it in 1 1/2 bytes. :-)
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: what better book ?
Next Topic: PHP/AJAX Problem
Goto Forum:
  

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

Current Time: Tue Nov 26 14:21:46 GMT 2024

Total time taken to generate the page: 0.02664 seconds