On Mon, Sep 1, 2008 at 10:38 AM, Gav <[EMAIL PROTECTED]> wrote:

>
>
> On Mon, Sep 1, 2008 at 10:10 AM, Gav <[EMAIL PROTECTED]> wrote:
>
>>
>>
>> On Mon, Sep 1, 2008 at 9:23 AM, Evert Lammerts <[EMAIL PROTECTED]>wrote:
>>
>>> 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.
>>>
>>
>> aha, excellent explanation , and $db2 = clone$db; worked fine!
>>
>> I was reading my way round php.net and getting closer I think, your
>> explanation and probably saved my a few days , so thanks.
>>
>
> hmm, did I speak to soon, it does work well for the whole list, but as soon
> as you select a region or speciality then it all goes pear shaped, I'll keep
> looking.
>

Ok, sorted that too, all is well again, sorry for noise.


>
> Gav...
>
>
>

Reply via email to