I try to rewrite this Python code in PHP. Currently I'm debugging it and strange thing happens: when I add var_dump in the piece of code, where Apache2 error log reports:
HP Fatal error: Call to a member function setext() on a non-object
then Firefox crushes and error.log claims:
[core:notice] [pid 2090] AH00052: child pid 14768 exit signal Segmentation fault (11)
and
Maximum execution time of 30 seconds exceeded
Caused by following function (var_dump is commented out):
function load($filename){
/***************************************************************
Load in a database and interpret it as a network
First column must be unique keys which define the instance units.
Each column is a pool (names, gangs, ages, etc).
Every row is mutually excitory.
****************************************************************/
global $units, $pools, $unitByName;
$units = array();
$pools = array();
$handle = fopen($filename, "r");
while (($line = fgets($handle)) !== false) {
$relatedUnits = preg_split('/\s+/', $line);
if (empty($relatedUnits)) continue;
$key = count($units);
foreach ($relatedUnits as $k => $ru){
if ($k >= count($pools)){
$pools[] = new Pool;
}
$pool = $pools[$k];
if (in_array($ru, $unitByName)){
$unit = $unitByName[$ru];
} else {
$unit = new Unit($ru, $pool);
$units[] = $unit;
}
$pool->addMember($unit);
if ($k > 0){
$units[$key]->addExciter($unit);
$unit->addExciter($units[$key]);
}
}
}
fclose($handle);
//var_dump($pools);
}
Without var_dump
code executes properly. Here whole code is pasted (it's still buggy, I'm aware of this ;)