Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7

Thread: ->

  1. #1
    Registered User
    Join Date
    Jun 2002
    Location
    Arizona
    Posts
    175
    Thanks
    0
    Thanked 0 Times in 0 Posts

    ->

    what is " -> " ?

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Posts
    553
    Thanks
    0
    Thanked 0 Times in 0 Posts
    As in object, property relationship?

    G

  • #3
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    That's easy. It's an arrow.


    Ok ok. That particular arrow in PHP is a way to refer to a method or variable of an object. An object such as a class is a good example:

    PHP Code:
    <?php

    class HelloWorld {

        var 
    $hello;

        function 
    HelloWorld(){
            
    $this->hello "Hello PHP newbie";
        }
        
        function 
    say_hello(){
            return 
    $this->hello;
        }
    }

    $my_class = new HelloWorld;
    echo 
    $my_class->say_hello();


    ?>
    That is just a simple example of creating a class and putting a function in there that returns a string. To refer to the function within that class we first create an instance of it

    $my_class = new HelloWord;

    then to access the function within it we use the arrow

    $my_class->function_name();
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #4
    Registered User
    Join Date
    Jun 2002
    Location
    Arizona
    Posts
    175
    Thanks
    0
    Thanked 0 Times in 0 Posts
    aahhh ok.. cool thanks

  • #5
    Registered User
    Join Date
    Jun 2002
    Location
    Arizona
    Posts
    175
    Thanks
    0
    Thanked 0 Times in 0 Posts
    what a second...

    sense when did you need var for a variable?

    what on earth is a class? i can't find it on php.net

    new? what is new?

  • #6
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    PHP has the capability of doing object oriented programming. A class is simply a way to package up functions to perfom certain tasks. This class is considered an object. When you want to use that object you have to create an instance of it. In object oriented programming this is called object instantiation. The new keyword is used to create an instance of an object like so:

    $my_class = new HelloWorld;

    This creates an instance of the object class HelloWorld and assigned to the variable $my_class. That variable acts as a reference and holds the object you just created.

    Here is a decent tutorial that goes into in more depth.

    http://www.zend.com/zend/tut/class-intro.php

    It is a very useful feature of PHP.

    Here is some more about object oriented programming on php.net:

    http://www.php.net/manual/en/language.oop.php
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #7
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Originally posted by Phip
    what a second...

    sense when did you need var for a variable?

    since I put it inside the class. Variables and functions inside a class are referred to as member variables and member functions. This mean that they are a member of that object. The object being the class.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •