Attempt to assign property of non-object in...
Posted on
16th Feb 2014 07:03 pm by
admin
I'm having issues with the following function in PHP 5...
function getTreeWithChildren()
{
Did you know?Explore Trending and Topic pages for more stories like this.
$category_id = $this->fields['id'];
$parent_id = $this->fields['parent'];
$this->DB->build( array( 'select' => join(',', $this->getFields()),
'from' => $this->table,
'order' => $this->fields['sort']
) );
$this->DB->execute();
// create a pseudo root level object
$root = new stdClass;
$root->$category_id = 0;
$root->children = array();
$arr = array($root);
// populate array and create empty child array
while ($row = $this->DB->fetch()) {
$arr[$row->$category_id] = $row;
$arr[$row->$category_id]->children = array();
}
// build child data
foreach ($arr as $id => $row) {
if (isset($row->$parent_id))
$arr[$row->$parent_id]->children[$id] = $id;
}
return $arr;
}
I'm getting the error
QuoteAttempt to assign property of non-object in ... on line 391
which is...
$arr[$row->$category_id]->children = array();
I've tried typecasting "$this->DB->fetch()" to an object with...
while ($row = (object) $this->DB->fetch()) {
but get a maximum execution time exceeded error instead.
The code was originally written for PHP 4 so I suspect it might be a way the objects are handled and the use of stdClass()?
I'd be extremely grateful if somebody could give me pointers to make this PHP5 compatible (5.2.9)? Thanks in advance
No comments posted yet
Your Answer:
Login to answer
84
54
Other forums
Help with PHP Calendar code...
Hello, I'm new to this forum and I'm glad I found it.
I wrote this code for a PHP calendar as an
form problem
Hi all, I think this is going to be easy to resolve but for I have been looking at it to long and I
count only commas outside parenteses
I have a sql table containing
id - query - query name
the first page contains a drop down men
Oracle Text CTX_DOC.snippet slow
I have a table (FILE_TABLE) that contains a blob column (ft_file) and I have created the following O
Blogging s/w
heya frndz!!! i want to start a blog.... m looking for a s/w like oscommerce which is thr for e-comm
Binding 2 UDP sockets on same port, connected to different destinations, 1 receives
Hello,
My application wants to send/recv data to 2 different UDP ports on a remote computer, us
Convert array to string and write to csv file
I am looking to write a MySQL query to a csv file.
At the minute I:
check for the orig
upload only text files
hi guys i want to upload only text like like (pdf,note pad and ofiice files) so can any one please t
Add code to enable passing of checkbox variable on login
Ok, I have a login page, but want to add a checkbox that when checked and successful login is made i
Putting double spaces instead of single spaces
Im looking at trying to replace all single spacing between fields with double spacing
At pres