Silly Question -> ( OO Syntax )

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
denz
Forum Newbie
Posts: 18
Joined: Fri Jun 24, 2005 4:18 pm

Silly Question -> ( OO Syntax )

Post by denz »

What does -> do in a script?

Thanks!

:D
djot
Forum Contributor
Posts: 313
Joined: Wed Jan 14, 2004 10:21 am
Location: planet earth
Contact:

Post by djot »

read about object oriented programming (OOP) on your favorite php website...
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

$a->c();

$a is a object which is just a reference to a class
-> kinda means like to that which you will understand in 2 seconds
c() is the function within the class

so it goes class to function in class. understand? probebly not, its hard to get the idea but after you figure it out its quite helpful
djot
Forum Contributor
Posts: 313
Joined: Wed Jan 14, 2004 10:21 am
Location: planet earth
Contact:

Post by djot »

shiznatix wrote:understand? probebly not
right :)
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

To delve deeper... In *very* basic terms a class is a collections of functions:

Code: Select all

class myClass {

    function a($x) {
        return 3*$x;
    }

    function b($y) {
        return 2*$y;
    }

}
That syntax would basically give access to the functions in "myClass".

Code: Select all

$myClass = new myClass; //Hmm... that's called instantiating (making the class ready to use)

$var1 = $myClass->a(4); // 3*4 == 12
$var2 = $myClass->b(1); // 2*1 == 2
It gets much more advanced if you read up but that's what the syntax you mention is for in any case ;)
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

The '->' is called a path name separator. The OOP section of the PHP Manual talks about the path name separator, what it does and how it works. Just be watchful, going into OOP makes it difficult to return to regular direct script development. :lol:

I had asked this question on this forum once before. You can see the thread by clicking here. Also, there is another thread on this topic asked at the CodingForums website.

Hope it helps. Enjoy OOP'ing. (Man that sounds bad...)
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

Post by Dale »

Thanks for this post, as it's teached me a few new things.
denz
Forum Newbie
Posts: 18
Joined: Fri Jun 24, 2005 4:18 pm

Post by denz »

great! thanks for your posts, will give me some more background reading to do and will teach me a thing or two!

Thanks
Post Reply