Есть некий скрипт
function Execute($sql,$inputarr=false)
{
if ($this->fnExecute)
{
$fn = $this->fnExecute;
$ret = $fn($this,$sql,$inputarr);
if (isset($ret))
{
return $ret;
}
}
if ($inputarr !== false)
{
if (!is_array($inputarr))
{
$inputarr = array($inputarr);
}
$element0 = reset($inputarr);
# is_object check because oci8 descriptors can be passed in
$array_2d = $this->bulkBind && is_array($element0) && !is_object(reset($element0));
//remove extra memory copy of input -mikefedyk
unset($element0);
if (!is_array($sql) && !$this->_bindInputArray)
{
// @TODO this would consider a '?' within a string as a parameter...
$sqlarr = explode('?',$sql);
$nparams = sizeof($sqlarr)-1;
if (!$array_2d)
{
// When not Bind Bulk - convert to array of arguments list
$inputarr = array($inputarr);
}
else
{
// Bulk bind - Make sure all list of params have the same number of elements
$countElements = array_map('count', $inputarr);
if (1 != count(array_unique($countElements)))
{
$this->outp_throw(
"[bulk execute] Input array has different number of params [" . print_r($countElements, true) . "].",
'Execute'
);
return false;
}
unset($countElements);
}
// Make sure the number of parameters provided in the input
// array matches what the query expects
$element0 = reset($inputarr);
if ($nparams != count($element0)) {
$this->outp_throw(
"Input array has " . count($element0) .
" params, does not match query: '" . htmlspecialchars($sql) . "'",
'Execute'
);
return false;
}
// clean memory
unset($element0);
foreach($inputarr as $arr)
{
$sql = ''; $i = 0;
//Use each() instead of foreach to reduce memory usage -mikefedyk
while(list(, $v) = each($arr))
{
$sql .= $sqlarr[$i];
// from Ron Baldwin <ron.baldwin#sourceprose.com>
// Only quote string types
$typ = gettype($v);
if ($typ == 'string')
{
//New memory copy of input created here -mikefedyk
$sql .= $this->qstr($v);
}
else if ($typ == 'double') {
$sql .= str_replace(',','.',$v); // locales fix so 1.1 does not get converted to 1,1
}
else if ($typ == 'boolean') {
$sql .= $v ? $this->true : $this->false;
}
else if ($typ == 'object')
{
if (method_exists($v, '__toString'))
{
$sql .= $this->qstr($v->__toString());
}
else
{
$sql .= $this->qstr((string) $v);
}
}
else if ($v === null)
{
$sql .= 'NULL';
}
else
{
$sql .= $v;
}
$i += 1;
if ($i == $nparams)
{
break;
}
} // while
if (isset($sqlarr[$i]))
{
$sql .= $sqlarr[$i];
if ($i+1 != sizeof($sqlarr)) {
$this->outp_throw( "Input Array does not match ?: ".htmlspecialchars($sql),'Execute');
}
}
else if ($i != sizeof($sqlarr)) {
$this->outp_throw( "Input array does not match ?: ".htmlspecialchars($sql),'Execute');
}
$ret = $this->_Execute($sql);
if (!$ret) {
return $ret;
}
}
}
else
{
if ($array_2d)
{
if (is_string($sql))
{
$stmt = $this->Prepare($sql);
}
else
{
$stmt = $sql;
}
foreach($inputarr as $arr)
{
$ret = $this->_Execute($stmt,$arr);
if (!$ret)
{
return $ret;
}
}
}
else
{
$ret = $this->_Execute($sql,$inputarr);
}
}
}
else
{
$ret = $this->_Execute($sql,false);
}
return $ret;
}
В нем возникает проблема с each() который заблокирован на версиях PHP 7.2
while(list(, $v) = each($arr))
Помогите переписать, я вообще впервые вижу такой метод работы с массивом. И не могу понять что автор там нагородил, и зачем вообще.. что бы память экономить?
Ничита нипанятна.. Надо в общем срочно поправить как нибудь этот обработчик, а то у меня уже подгорает...