SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot ameerulislam's Avatar
    Join Date
    Jul 2011
    Posts
    145
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    object oriented question

    what does this mean?

    PHP Code:
    $this->_ticketInfo = new ticketInfo(); 
    loading object into another object ?

  2. #2
    Avid Logophile silver trophy
    ParkinT's Avatar
    Join Date
    May 2006
    Location
    Central Florida
    Posts
    2,343
    Mentioned
    192 Post(s)
    Tagged
    4 Thread(s)
    Actually, it appears, there is a property (private and so named with a leading underscore) that is intended to contain an instance of the ticketInfo class. That is not unusual at all.
    Not quite an object loaded into another object.. But sort-of, yes.
    Don't be yourself. Be someone a little nicer. -Mignon McLaughlin, journalist and author (1913-1983)


    Git is for EVERYONE
    Literally, the best app for readers.
    Make Your P@ssw0rd Secure
    Leveraging SubDomains

  3. #3
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,182
    Mentioned
    67 Post(s)
    Tagged
    2 Thread(s)
    Your assign a new object to a variable, that so happens to be inside of a class. There is no difference between the following:

    Code PHP:
    $ticketInfo = new ticketInfo;

    and

    Code PHP:
    class MyNewClass {
        private $_ticketInfo;
        public function __construct() {
            $this->_ticketInfo = new ticketInfo;
        }
    }

    Its just that the variables have different scope. Take this one for example though:

    Code PHP:
    $ticketInfo = new ticketInfo;
     
    class MyNewClass {
        private $_ticketInfo;
        public function __construct(ticketInfo $ticketInfo) {
            $this->_ticketInfo = $ticketInfo;
        }
    }

    The last example here is called dependency injection. Now $this->_ticketInfo is a pointer to $ticketInfo defined before hand. Anything done to $this->_ticketInfo will actually be modifying / reading from the original variable.


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
  •