(apologies if this message is a duplicate -- my news server seems to
have problems)
Greetings,
When using PHP 4, this:
// ex. 1
class A {
function A(&$obj) {
$this->object =& $obj; // =& not needed?
}
}
is one reference too many: it should be
// ex. 2
class A {
function A(&$obj) {
$this->object = $obj; // = instead of =&
}
}
because $obj is already a reference when it enters the constructor, is
that correct?
Further question: when I upgrade to PHP 5, should I remove the & in
constructor to get the same effect? Objects are automatically passed by
reference in PHP 5, did I get that correctly? So the PHP 5 version would be:
// ex. 3
class A {
function A($obj) { // automatically passed by reference?
$this->object = $obj; // but what happens here?
}
}
But what happens in the $this->object = $obj; line in PHP 5? Is
$this->obj now a reference to a reference, as in ex. 1, assuming I
understood that piece of code correctly? If so, how do I get the ex. 2
behaviour in PHP 5?
Thanks,
Jan Pieter Kunst
--
Sorry, <devnull@cauce. org> is een "spam trap".
E-mail adres is <jpk"at"akamail .com>, waarbij "at" = @.
have problems)
Greetings,
When using PHP 4, this:
// ex. 1
class A {
function A(&$obj) {
$this->object =& $obj; // =& not needed?
}
}
is one reference too many: it should be
// ex. 2
class A {
function A(&$obj) {
$this->object = $obj; // = instead of =&
}
}
because $obj is already a reference when it enters the constructor, is
that correct?
Further question: when I upgrade to PHP 5, should I remove the & in
constructor to get the same effect? Objects are automatically passed by
reference in PHP 5, did I get that correctly? So the PHP 5 version would be:
// ex. 3
class A {
function A($obj) { // automatically passed by reference?
$this->object = $obj; // but what happens here?
}
}
But what happens in the $this->object = $obj; line in PHP 5? Is
$this->obj now a reference to a reference, as in ex. 1, assuming I
understood that piece of code correctly? If so, how do I get the ex. 2
behaviour in PHP 5?
Thanks,
Jan Pieter Kunst
--
Sorry, <devnull@cauce. org> is een "spam trap".
E-mail adres is <jpk"at"akamail .com>, waarbij "at" = @.
Comment