I
I
I'm Yoda2019-04-15 13:56:06
1C-Bitrix
I'm Yoda, 2019-04-15 13:56:06

What is the reason for this behavior, Fetch () is broken, what is the trouble?

Hi all!
It is not clear why Fetch() stopped working for the highload object.

$HLObject = $HLDataClass::getList(array(
        "select" => array("*"),
        "filter" => $arFilter
));

debug($HLObject); // выводит объект, как и было изначально

while ($arHLItem = $HLObject->Fetch()) {
        debug($arHLItem);  // пусто, пару дней назад было всё ок!
}

I'm at a loss! What is the reason for this behavior?
debug() - just a wrapper for print_r()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Nikolaev, 2019-04-15
@Anadi

Good afternoon Author.
First: stop using print_r to display results, look at least through var_dump() (because Bitrix has objects referring to itself in one way or another and you can get into recursion).
Secondly: if you entered the while, then there is data, if you did not enter it, then there is no data.
Thirdly: from version 18, you can no longer fetch, but use foreach.
Try the following code:

\ob_start();
echo PHP_EOL."<pre>".PHP_EOL;

$highloadItems = $HLDataClass::getList(array(
  "select" => ["*"],
  "filter" => $arFilter
));

var_dump([
  'filter' => $arFilter,
  'rowsCount' => $highloadItems->getSelectedRowsCount()
]);

foreach ($highloadItems as $highloadItem)
{
  var_dump( (array) $highloadItem );
}

\file_put_contents($_SERVER['DOCUMENT_ROOT'].'/uplod/testlog.log', \ob_get_clean(), FILE_APPEND);

Actually, the code will try to get all the data by the arFilter filter, will output this array and the number of found elements to the log. Then each found element as an associative array.
The output will redirect to the /upload/testlog.log file from the root of your site.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question