On Jul 30, 2007, at 12:05 AM, Tom Ray [Lists] wrote:
Ken Tozier wrote:
Hi
I'm trying to assign two fields of an object returned from a MySQL
query and have stumbled upon the most bizarre PHP bug where I
can't create two arrays in succession.
Here's the MySQL query with two dummy fields to be filled in later
select *, 0 as dummy_1, 0 as dummy_2 from table
Here's how I'm grabbing the query results
$result = array();
while ($row = mysql_fetch_object($query_result))
{
$result[] = $row;
}
Once that's done, I try to set two of the rows to arrays like this
$result-> dummy_1 = array(1, 2, 3, 4);
$result-> dummy_2 = array('a', 'b', 'c', 'd');
If I comment out either of the above lines, the script works but
with both uncommented, it seems to drop dead. It doesn't even
return an error.
Is this all of your code?
No. Here's the full function:
function get_document_type_for_pub($inPubID)
{
$query = "select doc_type.*, 0 as rect, 0 as usable_rect, 0 as
usable_width, 0 as usable_height, 0 as column_width, 0 as
column_offsets, 0 as box_widths from publication, doc_type where
publication.id=".$inPubID." and publication.doc_type=doc_type.id";
$queryResult = $this->db->query_database($query);
$result = $queryResult[0];
// convert numbers
$result->id += 0;
$result->page_width += 0.0;
$result->page_height += 0.0;
$result->top_margin += 0.0;
$result->left_margin += 0.0;
$result->bottom_margin += 0.0;
$result->right_margin += 0.0;
$result->column_count += 0;
$result->gutter_width += 0.0;
$result->folio_height += 0.0;
$result->usable_width += 0.0;
$result->usable_height += 0.0;
$result->column_width += 0.0;
// calculate derived values
$result->usable_width = $result->page_width - $result->left_margin -
$result->right_margin;
$result->usable_height = $result->page_height - $result->top_margin
- $result->bottom_margin;
$result->column_width = ($result->usable_width - $result-
>gutter_width * ($result->column_count - 1)) / $result->column_count;
/*------------------------------------------------------*/
/* Next two lines are where the problem starts */
/* If I comment either of them out the script runs */
/* but with both uncommented, it dies
/*------------------------------------------------------*/
// create the rect and usable rect records
$result->rect = array(0, 0, $result->page_width, $result-
>page_height);
$result->usable_rect = array($result->left_margin, $result-
>top_margin, $result->usable_width, $result->usable_height);
// create the offset and box width arrays
$offsets = array();
$widths = array();
$left = $result->left_margin;
$width = $result->column_width;
$inc = $result->column_width + $result->gutter_width;
for ($i = 0; $i < $result->column_count; $i++)
{
$offsets[] = $left;
$widths[] = array('column_width'=> $i + 1, 'point_width'=> $width);
$left += $inc;
$width += $inc;
}
$result->column_offsets = $offsets;
$result->box_widths = $widths;
return $result;
}
Do you have some sort of output display for your results?
No. Once it hits the "create the rect and usable rect records"
assignments, it's like the script didn't even get called. Nothing
returns.
Does PHP generally return errors to the browser?
I'm not using a browser, I'm making direct calls to the script from a
Cocoa class on a Mac
Does that script run on the same machine?
Yes. I'm doing all development on my MacBook and the scripts all live
in my local web folder.
If it's on another machine is that machine running the same
version? I ran this on a server with Apache 2.2.4, PHP 5.2.3 and
mySQL 5.0.18. Have you referenced that other script to make sure
that it *is* exactly the same?
I cut and pasted it from its original home to a new script and it
stopped working.
Thanks for replying Tom. I'll check out the php.ini settings tomorrow
Ken
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php