CodeIgniter Forums
ErrorException Trying to access array offset on value of type null - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: ErrorException Trying to access array offset on value of type null (/showthread.php?tid=77501)



ErrorException Trying to access array offset on value of type null - mrardiyansyah - 09-08-2020

I just upgraded XAMPP and PHP version 7.49 and opened a project under development getting an error "ErrorException

Trying to access array offset on value of type null" but previously there was no such error. Can anyone solve the problem?


RE: ErrorException Trying to access array offset on value of type null - Omar Crespo - 09-09-2020

Can you show the code lines where the error is??


RE: ErrorException Trying to access array offset on value of type null - mrardiyansyah - 09-10-2020

(09-09-2020, 03:57 PM)Omar Crespo Wrote: Can you show the code lines where the error is??
Code :

public function getAccess {
$
queryMenu = $this->getIdMenu($menu);

        $id_menu = $queryMenu['id_user_menu'];
}



RE: ErrorException Trying to access array offset on value of type null - Omar Crespo - 09-10-2020

You just missed the parameter, the correct function should be:

public function getAccess($menu)
{
$queryMenu = $this->getIdMenu($menu);
$id_menu = $queryMenu['id_user_menu'];
}

Also check 1 more thing:

Be sure that you are returning a valid value from getIdMenu($menu) function. For this sake, you have exceptions or a more simple way, a condition. Something like this:

public function getIdMenu($menu){

Here goes the code before this part

$variable = this->db->get();

$result = $variable->row_array();

if(!empty($result['id_user_menu']))

return $result;

return FALSE;

}


RE: ErrorException Trying to access array offset on value of type null - digindia - 06-24-2022

Hi,
I am getting the same Error as below, while receiving the Json API Response;
"title": "ErrorException",
    "type": "ErrorException",
    "code": 500,
    "message": "Trying to access array offset on value of type null",


And the Controller code is as below;

<?php

namespace App\Controllers;

use CodeIgniter\Controller;

class Rupiso_callback extends BaseController
{

    public function __construct(){
     
    }


public function index(){

$cryptedText = file_get_contents('php://input');
$responce = json_decode($cryptedText, true);

$type = $responce['type'];
$field1 = $responce['field1'];

if($type == "COLLOCTION"){
$agent_id = substr($field1, 4, 15);
} else{
$agent_id = substr($field1, 4, 15);
}

$tnxid = $responce['tnxid'];
$amount = $responce['amount'];
$payer_via = $responce['field2'];

$rupiso_log = [
'agent_id' => $agent_id,
'tnxid' => $tnxid,
'responce' => $cryptedText
];


$rupisoModel = new \App\Models\RupisoModel();
        $query = $rupisoModel->insert($rupiso_log);

}


}


?>


Please help to clear the issue..