Forum Moderators: coopster

Message Too Old, No Replies

$string->html('body'): what's meant by ->?

         

zozzen

6:26 pm on Jun 12, 2010 (gmt 0)

10+ Year Member



Hi,

in the CMS I'm using (mediawiki), many strings are displayed not in a way like "echo $content, but in a way like $this->html('bodytext') .

I try to search the meaning of -> but maybe the keyword for searching isn't good enough. I couldn't get any results....

Do you know what it is ?

Readie

7:53 pm on Jun 12, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's part of the syntax for PHP's object oriented programming - $this is used within the object code (internal) - any other variable name, and it's external, and you would find something a bit like this higher up in the code:

$string = new someClassName('some value');

Do a Google for "php oop" to find a few tutorials - although I don't advise trying to start off with the one on php.net :)

Matthew1980

8:59 pm on Jun 12, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi all,

To give it it's correct name: Scope resolution operator (->) and (::) both do the same thing. The name html in $this-html('value') refers to a function that is used within the class, if it was a variable it would be something like $this->html.

The string that is enclosed in the quotes is a variable that is passed into the function do that the function can perform processes depending on what's passed

There are a few tutorials out there, and as readie suggests, the one on php.net isn't the best starting point, but it is certainly worth giving a good read of - very informative examples once you get into the swing of things.

Cheers,
MRb

zozzen

8:05 am on Jun 13, 2010 (gmt 0)

10+ Year Member



thanks a lot! PHP's Object Oriented features look very new to me...i didn't know it is....

coopster

1:14 pm on Jun 14, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



It is often called the "arrow operator"

Matthew1980

3:38 pm on Jun 14, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



^^^
Hi there coopster,

I never knew as it was called that too! Makes me laugh when you get the error token back - its israelie for double colon, took me ages to find that out!

Cheers,
MRb

penders

3:16 pm on Jun 16, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



To give it it's correct name: Scope resolution operator (->) and (::) both do the same thing.


I don't believe '->' is ever called the scope resolution operator? Only the '::' (double colon) is the scope resolution operator. They do not do the same thing. Similar yes; same no - they are not interchangeable.

I'd go with coopster's 'arrow operator' for '->'

[edited by: penders at 4:10 pm (utc) on Jun 16, 2010]

Matthew1980

3:51 pm on Jun 16, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there Penders,

I recently needed to change a :: to -> because when I changed from E_ALL to E_STRICT, it picked up the fact that I was calling a function statically, I then changed :: to -> and prefixed the function name in the class with static, so that the error would be resolved, from that I thought as I could use :: & -> to the same end so long as I was defining the function 'static', this is why I thought as they both did the same job.

I just use -> as a pointer to a object/function within a class - admittedly I don't use :: too often so I may well get the context of use a bit mixed up ;)

Cheers,
MRb