"Kevin Bridges" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> 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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to