Re: newbie questions

From: Date: Sun, 29 Aug 2004 21:08:01 +0000
Subject: Re: newbie questions
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-195118@lists.php.net to get a copy of this message
"Kevin Bridges" <cyberswat@wispertel.net> wrote in message news:922722231.20040829132227@wispertel.net... > Greetings php-general, > > I'm just starting out with php ... judging from the posts I've been > reading on this list I'm thinking this question is so basic it might > almost be pathetic! I'm assuming the answers are in the php manual, > but I have not found the correct pages ... any pointers to manual > pages, tutorials, or an explanation would be greatly appreciated. > > <?php > require_once 'library/functions/dbConnect.php'; > class Content { > var $db = null; // PEAR::DB pointer > function Content(&$db) { > $this->db = $db; > } > } > ?> > > I'm writing my first class following an example I found on the web > and I have 2 questions. The constructor for Content accepts an > object ... why is &$db used instead of $db? > > I'm used to a this.varName syntax from other languages ... I grasp > what is happening with $this->db, but I don't understand the literal > translation of -> and would like help understanding. Hi Kevin, with PHP4 &$db means the value is passed by reference. Otherwise a copy of $db would be passed to the method. See here: http://de2.php.net/references With PHP5 variable assignments or passing variables to functions by reference is standard. $this->db is the PHP equal to this.varName. You access property db of the current object. Methods are called this way: $this->methodName() Hope this clears things up a bit. Best regards, Torsten Roehr

« previous php.general (#195118) next »