> The constructor for Content accepts an
>  object ... why is &$db used instead of $db?

&$variable means to pass the variable by reference (as opposed to
passing by value, which is the default). Instead of making a copy of
the variable, you are telling $this->db to point to the same point in
memory as the original $db - in effect you are using two names to
point to the same data. If you modify $this->db, $db will also be
modified and vice versa.

Only the author of the code could tell you exactly why they chose to
do things this way, but one possible reason is that when you close the
database link (using $this->db->disconnect() if it's PEAR::DB) it will
disconnect all the pointers to that link rather than just the one
local to the class (which would be the case if it was passed in by
value). Passing a reference rather than a copy also means you're not
storing multiple database links in memory which could affect
performance if the code was called often (e.g. on a busy web site).

Hope this helps,

Paul

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

Reply via email to