Results 1 to 6 of 6

Thread: Special purpose of ->

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2006
    Location
    Osaka
    Posts
    200

    Special purpose of ->

    Languages like vb,java, and .net.DOT operator is used to access class functions but in php -> operator is used.What is its speciality?

  2. #2
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099

    Re: Special purpose of ->

    Well in PHP the . (period) is used to join variables. Much like + in other langauges. Also i think that it is because PHP has take syntax from C++ and thats how class members are refered too.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2006
    Location
    Osaka
    Posts
    200

    Re: Special purpose of ->

    But i think in C++ .operator isn't used?

  4. #4
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099

    Re: Special purpose of ->

    Quote Originally Posted by slice
    But i think in C++ .operator isn't used?
    Both . and -> are used, ones for when the class is a pointer i think. It been ages since used C++. Back on topic, as far as i know its just to save confusion between a class method and adding variables. If you want to know more about OOP in PHP read the announcement at the top of the forum, and visualAds PHP 5 OOP tutorial

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: Special purpose of ->

    The reason that . wasn't used is simply that it was already taken. (Perl legacy.)
    The reason that -> was chosen as replacement is that it is used in C and C++.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  6. #6
    Frenzied Member
    Join Date
    Aug 2005
    Posts
    1,042

    Re: Special purpose of ->

    slice:

    in php -> operator is used.What is its speciality?
    the symbols (->) are used to access Class Members.

    If you have already defined a class (for example: TextBox) you can make
    an instance of it using the keyword (new) and then use it, like so:

    $box = new TextBoxSimple;
    $box->display();

    The result of evaluating this code will be to print an HTML fragment
    containing a table definition enclosing the text my text.

    (Not especially useful, but it’s a start.)

Posting Permissions

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



Click Here to Expand Forum to Full Width