Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #3643 > unrolled thread
| Started by | gaoqiang <gaoqiangscut@gmail.com> |
|---|---|
| First post | 2011-11-01 06:19 -0700 |
| Last post | 2011-11-01 23:36 +0000 |
| Articles | 8 — 5 participants |
Back to article view | Back to comp.lang.php
integer and string what's the difference ? gaoqiang <gaoqiangscut@gmail.com> - 2011-11-01 06:19 -0700
Re: integer and string what's the difference ? richard <member@newsguy.com> - 2011-11-01 11:23 -0400
Re: integer and string what's the difference ? Doug Miller <doug_at_milmacdotcom@example.com> - 2011-11-01 13:25 -0400
Re: integer and string what's the difference ? Denis McMahon <denismfmcmahon@gmail.com> - 2011-11-01 18:48 +0000
Re: integer and string what's the difference ? Balazs Nadasdi <yitsushi@gmail.com> - 2011-11-01 12:07 -0700
Re: integer and string what's the difference ? Denis McMahon <denismfmcmahon@gmail.com> - 2011-11-01 19:23 +0000
Re: integer and string what's the difference ? Denis McMahon <denismfmcmahon@gmail.com> - 2011-11-01 23:03 +0000
Re: integer and string what's the difference ? Denis McMahon <denismfmcmahon@gmail.com> - 2011-11-01 23:36 +0000
| From | gaoqiang <gaoqiangscut@gmail.com> |
|---|---|
| Date | 2011-11-01 06:19 -0700 |
| Subject | integer and string what's the difference ? |
| Message-ID | <f0db0e93-e49e-4bf9-99cc-7caa6fd7c298@g27g2000pro.googlegroups.com> |
1 <?php
2 require_once("config.php");
3 $now=time();
4 $value="abcd";
5 $key="1234";
6
7 $mem_server="localhost";
8 $mem_port=11211;
9 $memc=new Memcached;
10 $memc->addServer($mem_server,$mem_port);
11 $memc->set($key,$value);
12 $keys=array();
13 array_push($keys, 1234);
14 $rsts=$memc->getMulti($keys);
15 var_dump($rsts);
16 ?>
line 13: when using array_push($keys,"1234"),
it works fine. but not with 1234.
when using $memc->get,not getMulti, 1234 and
"1234" are the same.
I think this is a bug. any idea ?
[toc] | [next] | [standalone]
| From | richard <member@newsguy.com> |
|---|---|
| Date | 2011-11-01 11:23 -0400 |
| Message-ID | <15x9nbn4zc6gg.x15ymn9dh2a6.dlg@40tude.net> |
| In reply to | #3643 |
On Tue, 1 Nov 2011 06:19:01 -0700 (PDT), gaoqiang wrote:
> 1 <?php
> 2 require_once("config.php");
> 3 $now=time();
> 4 $value="abcd";
> 5 $key="1234";
> 6
> 7 $mem_server="localhost";
> 8 $mem_port=11211;
> 9 $memc=new Memcached;
> 10 $memc->addServer($mem_server,$mem_port);
> 11 $memc->set($key,$value);
> 12 $keys=array();
> 13 array_push($keys, 1234);
> 14 $rsts=$memc->getMulti($keys);
> 15 var_dump($rsts);
> 16 ?>
>
> line 13: when using array_push($keys,"1234"),
> it works fine. but not with 1234.
>
> when using $memc->get,not getMulti, 1234 and
> "1234" are the same.
>
> I think this is a bug. any idea ?
An integer is any numeric value.
Where some will argue that an integer is any whole number like 0 or 1.
But is "1" the same as 1? No it is not.
I once came across a web page that asked this simple question:
When does '1'+'1'='11'?
Notice the quotes.
in computer math 1+1=2.
But '1'+'1'='11'
In your code above, check line 13.
In line 5 you defined $key="1234".
In line 13, you are treating this value as an integer, not a string as you
defined it.
The quotes define the value as a string.
Try using the quotes around 1234 and see what happens.
In BASIC, a statement like a$="hello"+world would generate an error.
So to be correct it would have to be like this:
a$="hello"+str$(world)
str$() converts an integer to a string.
[toc] | [prev] | [next] | [standalone]
| From | Doug Miller <doug_at_milmacdotcom@example.com> |
|---|---|
| Date | 2011-11-01 13:25 -0400 |
| Message-ID | <j8pa39$2j2$1@dont-email.me> |
| In reply to | #3644 |
On 11/1/2011 11:23 AM, richard wrote:
> An integer is any numeric value.
Absolute nonsense. 123.456 is a numeric value, but it is not an integer.
> Where some will argue that an integer is any whole number like 0 or 1.
That is, in fact, the definition of an integer: a number that has no
fractional part. There is no "argument" about it, except by the uninformed.
C, the set of counting numbers, is {1, 2, 3, ...}
W, the set of whole numbers, is C and zero: {0, 1, 2, 3, ...}
I, the set of integers, is W and the negatives of C: { ..., -3, -2, -1,
0, 1, 2, 3, ...}
[toc] | [prev] | [next] | [standalone]
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Date | 2011-11-01 18:48 +0000 |
| Message-ID | <4eb03ee0$0$28448$a8266bb1@newsreader.readnews.com> |
| In reply to | #3644 |
On Tue, 01 Nov 2011 11:23:39 -0400, richard wrote:
> On Tue, 1 Nov 2011 06:19:01 -0700 (PDT), gaoqiang wrote:
>
>> 1 <?php
>> 2 require_once("config.php");
>> 3 $now=time();
>> 4 $value="abcd";
>> 5 $key="1234";
>> 6
>> 7 $mem_server="localhost";
>> 8 $mem_port=11211;
>> 9 $memc=new Memcached;
>> 10 $memc->addServer($mem_server,$mem_port); 11
>> $memc->set($key,$value);
>> 12 $keys=array();
>> 13 array_push($keys, 1234);
>> 14 $rsts=$memc->getMulti($keys);
>> 15 var_dump($rsts);
>> 16 ?>
> An integer is any numeric value.
Crap. An integer is any whole number. fractional values eg 1/2, 1/4,
567/24 etc are not integers, but they are numbers.
> Where some will argue that an integer is any whole number like 0 or 1.
> But is "1" the same as 1? No it is not.
>
> I once came across a web page that asked this simple question: When does
> '1'+'1'='11'?
> Notice the quotes.
> in computer math 1+1=2.
> But '1'+'1'='11'
Totally irrelevant. The OP clearly knows the difference between strings
and integers.
> In your code above, check line 13.
> In line 5 you defined $key="1234".
> In line 13, you are treating this value as an integer, not a string as
> you defined it.
>> 5 $key="1234";
>> 13 array_push($keys, 1234);
What on earth are you talking about? line 5 defines $key, line 13 uses
$keys, 2 totally different variables.
Richard, stop trying to debug people's code, you really have no idea what
you're talking about most of the time .... which I guess is nothing new.
Rgds
Denis McMahon
[toc] | [prev] | [next] | [standalone]
| From | Balazs Nadasdi <yitsushi@gmail.com> |
|---|---|
| Date | 2011-11-01 12:07 -0700 |
| Message-ID | <476405.510.1320174470853.JavaMail.geo-discussion-forums@yqan20> |
| In reply to | #3643 |
http://www.php.net/manual/en/memcache.set.php http://www.php.net/manual/en/memcache.get.php bool Memcache::set ( string $key , mixed $var [, int $flag [, int $expire ]] ) string Memcache::get ( string $key [, int &$flags ] ) array Memcache::get ( array $keys [, array &$flags ] ) If you add an integer based key, PHP convert it into string (get or set). I think if you are add as array (key list) PHP doesn't convert it into string (each item). But when you try to get a single value (1234) as an integer PHP automatically convert it because the function needs a string. Difference between Integer and String... In php: "1234" == 1234 # => true "1234" === 1234 # => false I hope, I was able to help you with something (and I don't misunderstand your problem).
[toc] | [prev] | [next] | [standalone]
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Date | 2011-11-01 19:23 +0000 |
| Message-ID | <4eb0472d$0$28635$a8266bb1@newsreader.readnews.com> |
| In reply to | #3643 |
On Tue, 01 Nov 2011 06:19:01 -0700, gaoqiang wrote: > line 13: when using array_push($keys,"1234"), it works fine. but not > with 1234. Memcached::set() and Memcached::get() both look for a string as the first (ie key) parameter. public bool Memcached::set ( string $key , mixed $value [, int $expiration ] ) public mixed Memcached::get ( string $key [, callback $cache_cb [, float & $cas_token ]] ) This suggests to me that keys must be strings, and so an array of keys must be an array of string values. Hence the numeric value 1234 may not be a valid key value even if it's in an array. Rgds Denis McMahon
[toc] | [prev] | [next] | [standalone]
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Date | 2011-11-01 23:03 +0000 |
| Message-ID | <4eb07aa6$0$28434$a8266bb1@newsreader.readnews.com> |
| In reply to | #3648 |
On Tue, 01 Nov 2011 19:23:25 +0000, Denis McMahon wrote: > This suggests to me that keys must be strings, and so an array of keys > must be an array of string values. Hence the numeric value 1234 may not > be a valid key value even if it's in an array. Following up on my own post, more testing suggests get / set appear to convert numeric keys to strings, but getMulti and setMulti don't seem to do so. I'd suggest an issue with php memcached, although the misbehaviour could conceivably be in the underlying server or client and not the php client wrapper. As you're using the php wrapper, that's probably where you should raise the issue. Rgds Denis McMahon
[toc] | [prev] | [next] | [standalone]
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Date | 2011-11-01 23:36 +0000 |
| Message-ID | <4eb08296$0$28584$a8266bb1@newsreader.readnews.com> |
| In reply to | #3649 |
On Tue, 01 Nov 2011 23:03:02 +0000, Denis McMahon wrote: > As you're using the php wrapper, that's probably where you should raise > the issue. Or vote on https://bugs.php.net/bug.php?id=59016 Rgds Denis McMahon
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.php
csiph-web