SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: Arrow Operator

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2006
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Arrow Arrow Operator

    How are people able to use the arrow operator like this:

    PHP Code:
    $this->something->something(); 

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    Guru in training bronze trophy SoulScratch's Avatar
    Join Date
    Apr 2006
    Location
    Maryland
    Posts
    1,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's used in object oriented code and can refer to a method or property of an object.

    Code:
    class person { 
    public $name; 
    }; 
    $john = new person(); 
    $john->name = 'John'; 
    echo $john->name;
    <WhiteVAL> Return: John
    Cross browser css bugs

    Dan Schulz you will be missed

  4. #4
    play of mind Ernie1's Avatar
    Join Date
    Sep 2005
    Posts
    1,252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    class one
    {
        public 
    $one "I'm in one<br />";

        public function 
    test()
        {
            echo 
    "I'm in one too";
        }
    }

    class 
    two
    {
        private 
    $d;

        public function 
    __construct()
        {
            
    $this->= new one();

            echo 
    $this->d->one;

            
    $this->d->test();
        }
    }

    $two = new two(); 
    Last edited by Ernie1; Jan 3, 2009 at 16:54.
    my mobile portal
    ghiris.ro

  5. #5
    Use The Cloud
    Join Date
    Jan 2006
    Location
    Boise, ID
    Posts
    556
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can also daisy chain methods by returning $this.

    PHP Code:
    class Test
    {
        public function 
    foo()
        {
            return 
    $this;
        }   
        
        public function 
    bar()
        {
            return 
    $this;
        }   
    }   


    $test = new Test();
    $test->foo()
         ->
    bar()
         ->
    foo()
         ->
    bar()
         ->
    foo()
         ->
    bar(); 
    Brad Hanson, Web Applications & Scalability Specialist
    ► Is your website outgrowing its current hosting solution?
    ► PM me for a FREE scalability consult!
    ► USA Based: Available by Phone, Skype, AIM, and E-mail.

  6. #6
    play of mind Ernie1's Avatar
    Join Date
    Sep 2005
    Posts
    1,252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    or even:
    PHP Code:
    class one
    {
        public 
    $one "I'm in one<br />";

        public function 
    test()
        {
            echo 
    "I'm in one too";
        }
    }

    class 
    two
    {
        private 
    $d;

        public function 
    __construct(one $d)
        {
            
    $this->$d;

            echo 
    $this->d->one;

            
    $this->d->test();
        }
    }

    $one = new one();

    $two = new two($one); 
    my mobile portal
    ghiris.ro

  7. #7
    SitePoint Enthusiast
    Join Date
    Oct 2006
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you all so much


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
  •