[thelist] another php question: object reference syntax

Jackson Yee jyee at vt.edu
Wed Jul 17 16:16:08 CDT 2002


----- Original Message -----
From: "Tom Dell'Aringa" <pixelmech at yahoo.com>
To: <thelist at lists.evolt.org>
Sent: Wednesday, July 17, 2002 16:20
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.

Which "rest of the universe" are you referring to, Tom?  PHP syntax was based
largely on C++ syntax, where -> has been the standard "member of pointer to"
for two decades.  Thus, you translate the C++ version

Foo* bar = new Foo();
bar->fubar();

to the PHP version

$bar = new Foo();
$bar->fubar();

you immediately see why operators were chosen for the way that they were.
Since PHP has no native pointer type as C++ does, all object references are
considered to be pointers, hence the use of the -> operator.

If you think having to type '->' instead of '.' is annoying though, wait until
you write your own PHP classes.  Instead of variables defaulting to class
scope in methods, you have to explicitly specify class scope by placing
$this-> in front of the variable name.  [g]  If the PHP designers ever start
adding polymorphism, templates, or multiple inheritance, I'd hate to see what
the syntax would look like then.

Regards,
Jackson Yee
jyee at vt.edu
http://www.jacksonyee.com/




More information about the thelist mailing list