Page 1 of 1

Free BSD and PHP

Posted: Mon Nov 15, 2004 9:24 pm
by BDKR
Hey,

Just some quick break down into what I'm doing here. I'm finishing up a script to manage fail over operations in a database cluster. The script is working fine. The development machines I've used have both been Linux on a 2.4 kernel and P5 (PHP5).

The script is actually going to be deployed on a FreeBSD box running 4.3.8 (I didn't use any P5 only features). Now honestly, I wouln't have thought it would make too much of a difference, but it seems that it does. While the script executes and doesn't kick out any errors. It's still not doing what it's supposed to do.

The layout of this code is basically an array of objects that represent all the databases in the cluster. There is an additional object that I call the Fail Boss. Each database object maintains a reference to the fail boss. As may be gathered from the name, the fail boss manages elections and fail over operations. Not all of it's functionality is yet in place, but what is there is working well...

...all the way until I run it on FreeBSD. Now I am about positive that the problem is an issue with dealing with references on FreeBSD builds. I am going to search bugs.php.net, but has anyone hear of or found any issues along these lines using FreeBSD?

Cheers,
BDKR

Posted: Tue Nov 16, 2004 8:24 am
by BDKR
Nevermind. The problem is that in PHP5, foreach returns objects by reference. PHP 4.x by copy. It sucks! :evil:

So, to iterate over an array of objects and net get bit in the @$$ becuase of the by copy behaviour, do this.

Code: Select all

foreach($array_of_objects as $name => $of_object)
    {
    $array_of_objects[$name]->objectMethod();
    }