При написании системы входа в систему для веб-проекта, над которым я работаю, я столкнулся с проблемой привязки неизвестного количества параметров и нашел эту функцию на страницах справки php.Мне всегда нравится полностью понимать кусочек кода, который я вкладываю во все, над чем я работаю, и я весьма озадачен тем, как работают несколько разделов этой функции.
Я прокомментировал все, что я понимаю (если я не прав, пожалуйста, дайте мне знать) и оставил свои основные вопросы в комментариях:
<?php
function getresult($stmt) {
//Define var for holding the result
$result = array();
//asign metadata of the statments result
$metadata = $stmt->result_metadata();
//grab the feilds from the metadata and assign to var
$fields = $metadata->fetch_fields();
//for loop with internal break
for (;;) {
//pointers array (not sure why this is an array and not a stdClass)
$pointers = array();
//row empty class
$row = new stdClass();
//set pointers array to the value of the passed statement (casting $pointers to mysqli_stmt class I assume(?)
$pointers[] = $stmt;
//iterate through all fields
foreach ($fields as $field) {
//each time set $fieldname to the name from the current element of $fields
$fieldname = $field->name;
//?? this is my big issue no idea whats going on here $row hasnt been set from what i can see, and no idea why its being refered to by reference and not value
$pointers[] = &$row->$fieldname;
}
//call bind result for all values
call_user_func_array(mysqli_stmt_bind_result, $pointers);
//internal break if
if (!$stmt->fetch()) {
//if there is nothing left to fetch break
break;
}
//set the result
$result[] = $row;
}
//free resources
$metadata->free();
//return result
return $result;
}
?>
Заранее спасибо!