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 Like 54 Dislike
Previous forums Next forums
Other forums

Pulling out some result data from MYSQL
Hey Guys,

I've built a PHP page that has a for just imagine something like registration form

Count of reciepients in php mailer
How can i sent a mail to large no of reciepients say 10,00,00 Using PHP MAILER

Error when call dll from oracle
Hi all, please help me!

I have dll write C language, I want call it from oracle procedur

socket makes browser hang...
I have a socket server, and I am having a problem at the moment...

A browser sends a http hea

Mouseover to edit (Ajax)
hi friends, can anyone help with the code behind to get this application working, please in VB (new

problem with query error
First Thanks to those who helped me on my previous posts, and the following code i'm using is not mi

getAlexaRank($url) function not working
I have made a function to get alexa rank
the site is here: http://mytestsite.rack111.com/1

constructor ?
i have written this program and made 3 constructors in the class and i want to call them in the main

whats wrong with my code please help!!!
this is the error


Warning: mysql_close(): supplied argument is not a valid MySQL-Link res

Mass activity scheduling
Hi experts,

Im facing some problems to deal with mass activity jobs.
When I run some

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash