SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast laresistance2's Avatar
    Join Date
    May 2011
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Question operator in PHP object syntax

    Hello,
    I want to know what it is that in PHP object syntax:

    PHP Code:
            public function myMethod($data) { 
                foreach (
    $data as $attribute => $value
                { 
                    [
    B]$method[/B] = 'set'.ucfirst($attribute); 
                     
                    if (
    is_callable(array($this$method))) 
                    { 
                        [
    B]$this->$method($value); [/B]
                    } 
                } 
            } 
    So I wonder what is the syntax $ this->$ method
    Why not do the same without the operator $ this->.
    What are the advantages of this syntax?

    Can you explain?
    thank you

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,506
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Did you try doing it without the $this-> ?

  3. #3
    SitePoint Addict
    Join Date
    Apr 2011
    Posts
    265
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    $this-> , inside class body, refers to the current object of that class, it makes the difference between property of the class and simple variable, class methods and functions.
    Free: Web Programming Courses HTML, CSS, Flash
    Web Programming: AJAX Course and PHP-MySQL Course video Lessons
    Good JavaScript and jQuery course for beginners


Tags for this Thread

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
  •