KBD

Keith Devens .com

Thursday, December 4, 2008 Flag waving
And if you go too far up, abstraction-wise, you run out of oxygen. Sometimes smart thinkers just don't... – Joel Spolsky
← No Windows XP ass wiping!Everything about Palm hacks →

Daily link icon Thursday, February 20, 2003

Reference identity in PHP and Python

Question: Is it possible to find out if two references point to the same thing in PHP and Python?

I know in Java you can just compare the references directly: a == b will tell you.

I know in C/C++ you can just compare pointer memory addresses: a == b will tell you.

I know in Perl you can stringify a reference and compare the resulting strings, since a stringified reference contains the memory address.

Ruby has object.equal?, etc. etc. I'm not quite sure about things like VB/VBscript and Javascript right now.

Anyway, the point is, references are pretty seamless in Python and PHP. Is there any way to find out that two variables aren't just equal, but point to the same thing?

← No Windows XP ass wiping!Everything about Palm hacks →

Comments XML gif

Adam Vandenberg wrote:

Python has the "is" operator for testing object identity.
By far the most common use of is / is not I've seen is testing an object against the singleton "None":

if stuff is not None:
# do something

∴ Adam Vandenberg | 21-Feb-2003 12:03pm est | #1478

Feel free to post a comment below. Please see my comment policy.

Formatting Rules (No HTML):

  • **bold**, *italic*, _underlined_, --strikeout--
  • "text"="url" creates a link, and URLs are auto-highlighted
  • Blockquote: Like e-mail, begin paragraph with > (greater-than sign)
  • Lists: begin paragraph with *,-, or + (unordered), or # (ordered)
  • Code block: ?!code:language=perl|php|sql|javascript|etc.{\n}...{\n}?!/code

:
(will be your IP address if blank)
: (optional)
(Will not be shown on site)

: (optional)
:

December 2008
SunMonTueWedThuFriSat
 123456
78910111213
14151617181920
21222324252627
28293031 



RSS feed RSS feed for Keith's Weblog
Atom feed Atom feed for Keith's Weblog
Weblog archive
Recent comments
  on 4 posts

Recent comments XML

Girls, please don't get breast implants

I have 34 A breast but at 22 years​old they seem to be growing again​which ...

76.64.120.153: Dec 3, 10:00am

Perl 6 1.0 in March?

Doh, my mistake. I'm aware of the​relation between Parrot and Rakudo​but I'...

Keith: Dec 2, 1:03am

Free image hosting sites

Well, TinyPic has this in its​FAQ:

> Images and videos is in​your accoun...

Keith: Dec 1, 1:13am

Join a NameValueCollection into a querystring in C#

Well with a lamba expression, this​is what I came up​with:

?!code:csharp...

Gustaf Lindqvist: Nov 30, 4:38pm

Generated in about 0.183s.

(Used 8 db queries)

mobile phone