0

im facing this error and i have no idea how to solve this.

[14-Jul-2021 19:59:46 UTC] PHP Notice: Only variables should be passed by reference in /home2/anmdeqdq/xxx/post/common.php on line 155

Line No. 155 is return array('status' => 'error', 'errors' => array_shift(array_values($errors)));

    if (!empty($errors)) {
    return array('status' => 'error', 'errors' => array_shift(array_values($errors)));
}

Full function code

function getfailsvalidator($db, $request, $id = null)
{
    $inputs = $request;
    $errors = Postvalidator($db, $inputs, $id);
    
    if (!empty($errors)) {
        return array('status' => 'error', 'errors' => array_shift(array_values($errors)));
    }

    foreach($inputs['entrys'] as $key => $n )
    {
        $entrytype = $n['type'];
        $v = EntryValidator($inputs['entrys'][$key], $entrytype);

        if (!empty($v)) {
            
            $keya = $key + 1;
            if($entrytype == "quizresult") {
                return array('status' => 'error', 'errors' => sprintf('Quiz #%s  Error: %s', $keya, array_shift(array_values($v))));
            }
            else if($entrytype == "quizquestion") {
                return array('status' => 'error', 'errors' => sprintf('Question #%s  Error: %s', $keya-$quizresultcount, array_shift(array_values($v))));
            }
            else if($entrytype=="poll") {
                return array('status' => 'error', 'errors' => sprintf('Question #%s  Error: %s', $keya, array_shift(array_values($v))));
            }
            else {
                return array('status' => 'error', 'errors' => sprintf('Entry #%s  Error: %s', $keya, array_shift(array_values($v))));
            }

        }
        else {
            if($entrytype == "poll"){
                $quizresultcount = 0;
            }

            if($entrytype == "quizquestion" or $entrytype == "poll") {

                if(!isset($n['answers']) or count($n['answers']) < 2){
                    return array('status' => 'error', 'errors' => sprintf('Question #%s  Error: %s', $key-$quizresultcount+1, 'Atleast 2 answers'));
                }

                foreach($n['answers'] as $ankey => $ann )
                {
                    $qv = QuizAnswerValidator($ann, $n['listtype']);

                    if (!empty($qv)) {
                        $keyaa = $ankey + 1;
                        return array('status' => 'error', 'errors' => sprintf('Entry #%s  Answer #%s  Error: %s', $key-$quizresultcount+1, $keyaa, array_shift(array_values($qv))));
                    }
                }
            }
        }
    }
}
Stephen
  • 1
  • 1

0 Answers0