Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: How is the -> symbol used

  1. #1
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default How is the -> symbol used

    can anyone explain how to use the -> symbol as in:
    PHP Code:
    <?php $this->lblLogout->Render(); ?>
    Last edited by Snookerman; 05-04-2009 at 07:30 PM. Reason: added [php] tags

  2. #2
    Join Date
    Jan 2008
    Posts
    4,167
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    The -> characters are used for accessing objects.
    Code:
    <?php
    class Write {
      function sayHi(){
        echo "Hello";
      }
    }
    $var = new Write();
    $var->sayHi();
    ?>
    Jeremy | jfein.net

  3. #3
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    Quote Originally Posted by Nile View Post
    The -> characters are used for accessing objects.
    more specifically they are to initiate a method.

    Code:
    class YOURCLASS 
    {
         public function FUNC()
         {
              /* something */
         }
         public function FTN($tring, $arr)
         {
              /* something else*/
         }
    }
    PHP Code:
    $var = new YOURCLASS();
    $var->FUNC(); /* initiate the FUNC method of the YOURCLASS class */

    $var->FTN('a1', ['z','y','w']); 

  4. #4
    Join Date
    Jan 2007
    Location
    The stage
    Posts
    568
    Thanks
    23
    Thanked 6 Times in 6 Posts

    Default

    okay, i also was about to ask this question but i saw it was already asked... would this be an appropriate use of it:
    PHP Code:
    function hi($name){
    echo 
    $name;
    }
    "hello"->hi(); 
    ?

  5. #5
    Join Date
    Jan 2008
    Posts
    4,167
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    No... The symbol is only used for classes(or OOP).
    Jeremy | jfein.net

  6. #6
    Join Date
    May 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    The "->" in PHP is used to access properties and functions of an object. To use it, you'll need an object to use it on, like this:

    Create a class (a blueprint for an object):
    PHP Code:
    class helloObject {
      public function 
    hi($name) {
        echo 
    "Hello " $name;
      }

    You can save this as a separate file, called helloObject.php. Then, in the script you want to use it in, first create an instance of your object with the "new" operator, and call the function you've defined in helloObject.php, passing it the name you want printed as a parameter:

    PHP Code:
    $object = new helloObject();
    $object->hi("Joe"); 
    This will produce the output:
    Code:
    Hello Joe
    ggalan, the code you posted is saying that the variable $this has an object called lblLogout as one of its properties, and this object in turn has a function called Render() - this line calls that function.

  7. #7
    Join Date
    Jan 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Pronounce it: ->

    Thank you guys. This really clears the idea of oop in php.

    Now, folks I just want to know how do you pronounce it. You know while working in a team some times you need to read your code. So, is there any standard pronunciation for the symbol " -> "?


  8. #8
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    I just say "arrow." But then, I don't talk about it much (aloud) with other programmers. Of course, I also say "S - Q - L" instead of "sequel."

  9. #9
    Join Date
    Jan 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to submit a link!

    Quote Originally Posted by traq View Post
    I just say "arrow." But then, I don't talk about it much (aloud) with other programmers. Of course, I also say "S - Q - L" instead of "sequel."

    Looks like you just wanted to submit a link! I asked "standard pronunciation". Spam!

  10. #10
    Join Date
    Jan 2008
    Posts
    4,167
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    "Submit a Link," what does that mean? He gave you an anwer, the link in his signature is his signature, it shows up every time he posts.

    I usually say "This variable accesses this class, and returns blah blah blah..." I don't think that there is a standard way to say it.
    Jeremy | jfein.net

Bookmarks

Posting Permissions

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