Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,12 @@
} elseif ($return === 'data') {
return $output;
} elseif (!empty($toSeparatePlaceholders)) {
$output['log'] = $log;
$modx->setPlaceholders($output, $toSeparatePlaceholders);
if(is_array($log)){
$output['log'] = $log;
$modx->setPlaceholders($output, $toSeparatePlaceholders);
}else {
$modx->setPlaceholders(['log' => $log], $toSeparatePlaceholders);
}
Comment on lines 57 to +63
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The wrong variable is being checked.

  • Problem: $output can be a string (when called via pdoPage with toSeparatePlaceholders), but the code does $output['log'] = $log, which in PHP 8 results in TypeError: Cannot access offset of type string.
  • In the code: $log is always a string (or an empty string), since it is formed as $log .= ' ' . print_r($pdoFetch->getTime(), 1) . ' '.
  • Consequence: the is_array($log) condition is almost always false, the else branch is executed, and only ['log' => $log] is included in placeholders, while the contents of $output are lost.

You need to check $output, not $log:

} elseif (!empty($toSeparatePlaceholders)) {
    if (is_array($output)) {
        $output['log'] = $log;
        $modx->setPlaceholders($output, $toSeparatePlaceholders);
    } else {
        $modx->setPlaceholders(['output' => $output, 'log' => $log], $toSeparatePlaceholders);
    }
}
  • If $output is an array: add log and set all placeholders from $output.
  • If $output is a string: set output and log as separate placeholders.

} else {
$output .= $log;

Expand Down