Re: Problem after moving servers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I'm pretty sure I found the problem - I should've spotted it earlier.

The function ProfileList::render gets a reference to the $db object by
its parameter &$db. While you loop over your results, you pass the
reference on to $this->des->load. I'm guessing that the definition of
$this->des->load is something like function load($id, $db);, in which
case it's not getting a reference to the $db object but an actual copy
in PHP4. Since PHP 5 there is a new object model that makes sure that
any variable that holds an object is actually just a handle to the
object - so whenever you pass it to a function you use it as a
reference instead of a copy.

To make it clear:

class test {
  var $a = 1;
  function aa() {
    $this->a++;
  }
}

$c = new test();
$d = $c;
$c->aa();
$d->aa();
var_dump ($c);

results in:
object(test)#1 (1) { ["a"]=>  int(3) }

This means you should first change the function definitions to not use
references for objects, so take away the & at every &$db parameter.

Second you need to create a new $db object for your $this->des->load
function before the while loop in ProfileList::render. I think the
safest option is to do something like $db2 = new Db(...). You can also
use the keyword clone to clone an object, but i'm not sure what this
does with your internal DB handle.... you could try and see what
happens. Just add $db2 = clone $db; right before the while loop. Call
$this->des->load with $db2 instead of $db.

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


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux