Threaded Comments
ExpressionEngine 2
Back to this add-on's main page
View Other Add-ons From Yuri Salimovskiy
Fixing PHP 5.4 ‘Message: Creating default object from empty value’
Support Request
totalserve
|
Posted: 29 October 2012 02:35 AM |
|
|
|
If you’re experiencing this E_STRICT warning, here’s the fix; recommend the developer applies this up-stream too.
Look around line 1312 of mod.threaded_comments.php for:
foreach ($query->result_array() as $row) { if ($first_comment_id==0 && $row['level']==0) $first_comment_id = $row['comment_id'];
Change to:
foreach ($query->result_array() as $row) { $this->comment[$row['comment_id']] = new stdClass(); $this->comment[$row['parent_id']] = new stdClass(); if ($first_comment_id==0 && $row['level']==0) $first_comment_id = $row['comment_id'];
|
|
|
totalserve
|
Posted: 30 October 2012 01:14 AM |
# 1
|
|
|
Sorry, here’s a better fix; to the developer - your code is a-little confusing. It looks like you’re a bit confused on when to use associate arrays and when to use objects and you are trying to incorrectly mangle the two together.
While my fix below will solve the E_STRICT warnings, it’s still bad style. Looking throughout the module you’re repetitively trying to assign values via object orientated methods to variables that aren’t objects (yet).
I would suggest you use either object orientated methods, or associate arrays, and not both.
foreach ($query->result_array() as $row) { $this->comment[$row['comment_id']] = is_object($this->comment) ? $this->comment : new stdClass(); if (!isset ($this->comment[$row['parent_id']])) { $this->comment[$row['parent_id']] = new stdClass(); } if ($first_comment_id==0 && $row['level']==0) $first_comment_id = $row['comment_id']; if ( !isset($this->comment[$row['comment_id']]->has_children)) $this->comment[$row['comment_id']]->has_children = false; $this->comment[$row['parent_id']]->has_children = true; if ($this->comment[$row['parent_id']]->has_children == true) { $this->comment[$row['parent_id']]->children[] = $row['comment_id']; }
|
|
|
Yuri Salimovskiy
|
Posted: 30 October 2012 02:49 AM |
# 2
|
|
Developer
|
Hi and thanks for the fix!
I’m in the process of completely rewriting the code, but not sure when that will happen, meanwhile your addition is very useful and will be added to next release. Thanks!
|
|
|