[thelist] another php question: object reference syntax

Jonathan_A_McPherson at rl.gov Jonathan_A_McPherson at rl.gov
Wed Jul 17 15:44:06 CDT 2002


Tom,

This is an inherited trait from the programming language that PHP derives
much of its syntax from -- C.

In C, suppose I have an object named "bar" that has a method named do_foo.

I can say:

bar.do_foo();

and it'll work fine. Now, suppose I create a _pointer_ to bar called quux:

quux = &bar;

quux is not bar; it's a pointer to bar. Therefore, I cannot say

quux.do_foo();

... I must instead say

quux->do_foo();

... which tells C to follow the pointer "quux." So in your example, "bar" is
likely a reference/pointer to an object with a do_foo() method, not an
actual object.

The syntax may seem odd, but it is exactly what many open-source developers
are used to, if they've ever done much work with C/C++ -- and most of them
have.

--
Jonathan McPherson, LMIT/SD&I
Software Engineer & Web Systems Analyst
email / jonathan_a_mcpherson at rl dot gov

-----Original Message-----
From: Tom Dell'Aringa [mailto:pixelmech at yahoo.com]
Sent: Wednesday, July 17, 2002 1:20 PM
To: thelist at lists.evolt.org
Subject: [thelist] another php question: object reference syntax


So far I can't find this in the manual so I'll ask here - I keep
seeing references to ojbect references in php as:

$bar->do_foo();

-> is about the silliest thing I've ever seen. PLEASE tell me you can
do $bar.do_foo(); like the rest of the universe does...

WHY would I want to constantly type "-" and ">", one a shift
character, one not, on opposite top/bottom of the keyboard, when I
can simply hit the period with finger? For an open source language,
that is truly nuts.

Tom



More information about the thelist mailing list