Bug #1578: Arrays of arrays breaking the parser
| From: | jesusmc at scripps dot edu | Date: | Mon, 21 Jun 1999 22:58:26 +0000 |
| Subject: | Bug #1578: Arrays of arrays breaking the parser | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-7361@lists.php.net to get a copy of this message | ||
From: jesusmc@scripps.edu
Operating system: Solaris 2.5.1
PHP version: 3.0.9
PHP Bug Type: Reproduceable crash
Bug description: Arrays of arrays breaking the parser
Problem:
A script making use of arrays of arrays breaks PHP 3.0.8 and 3.0.9, works with PHP 3.0.7
I coredumps or fails giving the message or both. When it fails, it gives the messages:
"
...
<br>
<b>Warning</b>: Variable $atom is not an array or string in
<b>clu2.php3</b> on line <b>62</b><br>
<br>
<b>Warning</b>: Variable $atom is not an array or string in
<b>clu2.php3</b> on line <b>63</b><br>
<br>
<b>Warning</b>: Variable $atom is not an array or string in
<b>clu2.php3</b> on line <b>64</b><br>
<br>
<b>Warning</b>: Variable $atom is not an array or string in
<b>clu2.php3</b> on line <b>65</b><br>
<br>
<b>Warning</b>: Variable $atom is not an array or string in
<b>clu2.php3</b> on line <b>66</b><br>
...
"
Consistently the first entry works and the rest don't.
The following is the script that break PHP 3.0.8 and 3.0.9 compiled as module of Apache or as stand
alone CGI. It works OK with 3.0.7
In all cases, PHP was compiled using (CGI case example):
./configure --prefix=/home/jesusmc/devel/php3 --with-gd=/asd/metallo1/database/gd1.3
--with-msql=/home/jesusmc/devel/msql --with-config-file-path=/homes/jesusmc/devel/php3
--enable-track-vars --enable-magic-quotes --with-mysql=/home/jesusmc/devel/mysql
--with-pgsql=/home/jesusmc/devel/pgsql
Script cluster.php3
<?php
// to pre-calculate the distances in clusters
// $Id: cluster.php3,v 1.1 1999/06/17 22:51:39 jesusmc Exp $
/*
* function to display contents of an array
* appropriately indented with tabs
*/
function print_array($valsarr,$tab="") {
static $tab;
while ( list($var,$value) = each($valsarr) ) {
if (!is_array($value)) {
echo $tab."VARIABLE: ".$var." -> VALUE:
".$value."<BR>\n";
} else { // item is itself an array
echo $tab."VARIABLE: ".$var." is an array<BR>\n";
print_array($value,$tab.="\t");
}
}
$tab = substr($tab,0,-1);
}
function coords($obj) {
return
array("x"=>$obj["x"],"y"=>$obj["y"],"z"=>$obj["z"]);
}
function getdist($coord1,$coord2) {
$d2 = 0;
while(list($k,$v) = each($coord1)) {
$d2 += pow(($coord1[$k] - $coord2[$k]),2);;
}
return sqrt($d2);
}
$link = mysql_pconnect("localhost");
mysql_select_db("edited");
$res = mysql_query("select distinct site_id from site where
is_cluster='y'",$link);
while ($tmp = mysql_fetch_row($res)) {
$sid[] = $tmp[0];
}
$nsites = count($sid);
for ($i=0; $i<$nsites; $i++) {
$tsid = $sid[$i];
$q = "select distinct site_id,ligand_id,symbol,x,y,z ";
$q .= " from atom where site_id='".$tsid."' and ligand_id like
'%s0lm'";
$res = mysql_query($q,$link);
$natoms=0;
while ($tmp = mysql_fetch_array($res)) {
$atom[$natoms++] = $tmp;
}
for ($j=0; $j<$natoms; $j++) {
for ($k=$j+1; $k<$natoms; $k++) {
$dist = getdist(coords($atom[$j]),coords($atom[$k]));
$record["source_id"] =
"'".substr($atom[$j]["site_id"],0,10)."'";
$record["site_id"] =
"'".$atom[$j]["site_id"]."'";
$record["ligand_id"] =
"'".$atom[$j]["ligand_id"]."'";
$record["atom1"] =
"'".$atom[$j]["symbol"]."'";
$record["atom2"] =
"'".$atom[$k]["symbol"]."'";
$record["distance"] = $dist;
$record["timestamp"] =
"'".date("YmdHis",time())."'";
print_array($record);
echo "<HR>";
#echo "$j $k $dist<BR><BR>\n";
/*
$inquery = "insert into cluster
(source_id,site_id,ligand_id,atom1,atom2,distance,updated) ";
$inquery .= " values
(".implode($record,",").")";
$inresult = mysql_query($inquery,$link);
if ($inresult) { echo "SUCCESS\n"; print_array($record); echo
"\n\n"; }
*/
}
}
}
?>
The tables were generated by using:
# site table
CREATE TABLE site (
source_id varchar(25) DEFAULT '' NOT NULL,
site_id varchar(25) DEFAULT '' NOT NULL,
metal char(2) DEFAULT '' NOT NULL,
metal_chain char(1),
is_cluster enum('n','y') DEFAULT 'n' NOT NULL,
geometry_id smallint(5) unsigned DEFAULT '0' NOT NULL,
class_id smallint(5) unsigned DEFAULT '0' NOT NULL,
function_id smallint(5) unsigned DEFAULT '0' NOT NULL,
nligands_s1 smallint(5) unsigned DEFAULT '0' NOT NULL,
nlig_protein smallint(5) unsigned,
nlig_nucleic smallint(5) unsigned,
nlig_metal smallint(5) unsigned,
nlig_water smallint(5) unsigned,
nlig_anion smallint(5) unsigned,
nlig_hetero smallint(5) unsigned,
nligands_s2 smallint(5) unsigned DEFAULT '0' NOT NULL,
apo_site enum('n','y') DEFAULT 'n' NOT NULL,
repr_phom enum('n','y') DEFAULT 'n' NOT NULL,
repr_lhom enum('n','y') DEFAULT 'n' NOT NULL,
repr_mdl enum('n','y') DEFAULT 'n' NOT NULL,
repr_chn enum('n','y') DEFAULT 'n' NOT NULL,
public enum('y','n') DEFAULT 'y' NOT NULL,
updated date DEFAULT '0000-00-00' NOT NULL,
stamp timestamp(14),
UNIQUE site_id_IDX (site_id),
KEY metal_IDX (metal),
KEY is_cluster_IDX (is_cluster),
KEY apo_site_IDX (apo_site),
KEY repr_phom_IDX (repr_phom),
KEY repr_lhom_IDX (repr_lhom),
KEY repr_mdl_IDX (repr_mdl),
KEY repr_chn_IDX (repr_chn),
KEY public_IDX (public),
KEY updated_IDX (updated),
KEY source_id_IDX (source_id),
KEY geometry_IDX (geometry_id),
KEY class_IDX (class_id),
KEY function_IDX (function_id),
KEY nligands_s1_IDX (nligands_s1),
KEY nligands_s2_IDX (nligands_s2)
);
#
# Dumping data for table 'site'
# WHERE: is_cluster='y'
#
INSERT INTO site VALUES
('1frd','pdb-1frd-_-fe-1','fe','_','y',3,6,3,4,4,0,0,0,0,0,12,'n','n','y','y','y','y','1999-0
6-14',19990614172137);
INSERT INTO site VALUES
('1isu','pdb-1isu-a-fe-1','fe','a','y',9,6,1,4,4,0,0,0,0,0,20,'n','n','y','y','y','y','1999-0
6-15',19990615163310);
INSERT INTO site VALUES
('1isu','pdb-1isu-b-fe-2','fe','b','y',9,6,3,4,4,0,0,0,0,0,20,'n','n','n','n','n','y','1999-0
6-15',19990615180406);
# atom table
CREATE TABLE atom (
site_id varchar(25) DEFAULT '' NOT NULL,
ligand_id varchar(30) DEFAULT '' NOT NULL,
symbol varchar(4) DEFAULT '' NOT NULL,
seqnum smallint(5) unsigned DEFAULT '0' NOT NULL,
x double(16,4),
y double(16,4),
z double(16,4),
public enum('y','n') DEFAULT 'y' NOT NULL,
updated date DEFAULT '0000-00-00' NOT NULL,
stamp varchar(16) DEFAULT '' NOT NULL,
KEY site_id_IDX (site_id),
KEY ligand_id_IDX (ligand_id),
KEY updated_IDX (updated),
KEY public_IDX (public),
KEY symbol_IDX (symbol),
UNIQUE atom_IDX (ligand_id,symbol,seqnum,stamp,updated)
);
#
# Dumping data for table 'atom'
# WHERE: ligand_id like '%s0lm'
#
INSERT INTO atom VALUES
('pdb-1irn-_-zn-1','pdb-1irn-_-zn-1-s0lm','zn',765,14.0030,26.0880,26.7150,'y','1999-06-02','
19990602112833');
INSERT INTO atom VALUES
('pdb-1plc-_-cu-1','pdb-1plc-_-cu-1-s0lm','cu',1548,7.0500,34.9600,18.7160,'y','1999-05-28','
19990528172159');
INSERT INTO atom VALUES
('pdb-1hca-_-zn-1','pdb-1hca-_-zn-1-s0lm','zn',2041,-6.6820,-1.5410,15.5630,'y','1999-06-04',
'19990604160830');
INSERT INTO atom VALUES
('pdb-1a4f-a-fe-1','pdb-1a4f-a-fe-1-s0lm','fe',1088,36.6930,17.5480,40.5390,'y','1999-06-08',
'19990608175706');
INSERT INTO atom VALUES
('pdb-1a4f-b-fe-2','pdb-1a4f-b-fe-2-s0lm','fe',2298,57.3420,-4.1540,22.3410,'y','1999-06-08',
'19990608182856');
INSERT INTO atom VALUES
('pdb-1cll-_-ca-1','pdb-1cll-_-ca-1-s0lm','ca',1135,1.7080,47.7760,24.1970,'y','1999-06-09','
19990609183020');
INSERT INTO atom VALUES
('pdb-1cll-_-ca-2','pdb-1cll-_-ca-2-s0lm','ca',1136,-2.1120,44.4380,13.3600,'y','1999-06-09',
'19990609185216');
INSERT INTO atom VALUES
('pdb-1cll-_-ca-3','pdb-1cll-_-ca-3-s0lm','ca',1137,30.4630,11.9620,10.4730,'y','1999-06-09',
'19990609201249');
INSERT INTO atom VALUES
('pdb-1cll-_-ca-4','pdb-1cll-_-ca-4-s0lm','ca',1138,29.1810,17.9630,0.8040,'y','1999-06-09','
19990609203451');
INSERT INTO atom VALUES
('pdb-1bbh-a-fe-1','pdb-1bbh-a-fe-1-s0lm','fe',969,24.3940,44.9620,56.8930,'y','1999-06-10','
19990610184224');
INSERT INTO atom VALUES
('pdb-1bbh-b-fe-2','pdb-1bbh-b-fe-2-s0lm','fe',1980,37.0350,25.2340,55.6390,'y','1999-06-10',
'19990610193726');
INSERT INTO atom VALUES
('pdb-1frd-_-fe-1','pdb-1frd-_-fe-1-s0lm','fe1',757,3.4280,22.1610,1.7620,'y','1999-06-14','1
9990614172137');
INSERT INTO atom VALUES
('pdb-1frd-_-fe-1','pdb-1frd-_-fe-1-s0lm','fe2',758,1.2700,22.9730,0.3620,'y','1999-06-14','1
9990614172137');
INSERT INTO atom VALUES
('pdb-1frd-_-fe-1','pdb-1frd-_-fe-1-s0lm','s1',759,1.7750,20.9300,0.9750,'y','1999-06-14','19
990614172137');
INSERT INTO atom VALUES
('pdb-1frd-_-fe-1','pdb-1frd-_-fe-1-s0lm','s2',760,2.9810,24.1680,1.0630,'y','1999-06-14','19
990614172137');
INSERT INTO atom VALUES
('pdb-1isu-a-fe-1','pdb-1isu-a-fe-1-s0lm','fe1',441,35.5410,37.8190,3.7680,'y','1999-06-15','
19990615163310');
INSERT INTO atom VALUES
('pdb-1isu-a-fe-1','pdb-1isu-a-fe-1-s0lm','fe2',442,33.2720,38.6400,2.4290,'y','1999-06-15','
19990615163310');
INSERT INTO atom VALUES
('pdb-1isu-a-fe-1','pdb-1isu-a-fe-1-s0lm','fe3',443,33.5850,36.0200,3.1800,'y','1999-06-15','
19990615163310');
INSERT INTO atom VALUES
('pdb-1isu-a-fe-1','pdb-1isu-a-fe-1-s0lm','fe4',444,35.1090,36.9990,1.2420,'y','1999-06-15','
19990615163310');
INSERT INTO atom VALUES
('pdb-1isu-a-fe-1','pdb-1isu-a-fe-1-s0lm','s1',445,35.4500,39.2150,1.9240,'y','1999-06-15','1
9990615163310');
INSERT INTO atom VALUES
('pdb-1isu-a-fe-1','pdb-1isu-a-fe-1-s0lm','s2',446,33.4060,37.8500,4.5610,'y','1999-06-15','1
9990615163310');
INSERT INTO atom VALUES
('pdb-1isu-a-fe-1','pdb-1isu-a-fe-1-s0lm','s3',447,35.8210,35.8010,3.0380,'y','1999-06-15','1
9990615163310');
INSERT INTO atom VALUES
('pdb-1isu-a-fe-1','pdb-1isu-a-fe-1-s0lm','s4',448,32.8460,36.9190,1.1640,'y','1999-06-15','1
9990615163310');
INSERT INTO atom VALUES
('pdb-1isu-b-fe-2','pdb-1isu-b-fe-2-s0lm','fe1',889,20.5550,33.0360,20.7290,'y','1999-06-15',
'19990615180406');
INSERT INTO atom VALUES
('pdb-1isu-b-fe-2','pdb-1isu-b-fe-2-s0lm','fe2',890,21.9130,34.9750,22.1450,'y','1999-06-15',
'19990615180406');
INSERT INTO atom VALUES
('pdb-1isu-b-fe-2','pdb-1isu-b-fe-2-s0lm','fe3',891,23.3020,33.2740,20.4850,'y','1999-06-15',
'19990615180406');
INSERT INTO atom VALUES
('pdb-1isu-b-fe-2','pdb-1isu-b-fe-2-s0lm','fe4',892,22.1510,32.3330,22.7630,'y','1999-06-15',
'19990615180406');
INSERT INTO atom VALUES
('pdb-1isu-b-fe-2','pdb-1isu-b-fe-2-s0lm','s1',893,20.2360,33.6320,22.9280,'y','1999-06-15','
19990615180406');
INSERT INTO atom VALUES
('pdb-1isu-b-fe-2','pdb-1isu-b-fe-2-s0lm','s2',894,21.7370,34.8250,19.8220,'y','1999-06-15','
19990615180406');
INSERT INTO atom VALUES
('pdb-1isu-b-fe-2','pdb-1isu-b-fe-2-s0lm','s3',895,21.9910,31.4430,20.7040,'y','1999-06-15','
19990615180406');
INSERT INTO atom VALUES
('pdb-1isu-b-fe-2','pdb-1isu-b-fe-2-s0lm','s4',896,23.8310,33.9820,22.7210,'y','1999-06-15','
19990615180406');
# cluster table (populated by the script cluster.php3)
CREATE TABLE cluster (
source_id varchar(20) DEFAULT '' NOT NULL,
site_id varchar(20) DEFAULT '' NOT NULL,
ligand_id varchar(30) DEFAULT '' NOT NULL,
atom1 varchar(5) DEFAULT '' NOT NULL,
atom2 varchar(5) DEFAULT '' NOT NULL,
distance float(10,2) unsigned DEFAULT '0.00' NOT NULL,
updated timestamp(14),
KEY source_id (source_id),
KEY site_id (site_id),
KEY ligand_id (ligand_id),
KEY atom1 (atom1),
KEY atom2 (atom2)
);