CodeIgniter icon indicating copy to clipboard operation
CodeIgniter copied to clipboard

trim(): Passing null to parameter #1

Open motoroller1983 opened this issue 3 years ago • 8 comments

A PHP Error was encountered

Severity: 8192

Message: trim(): Passing null to parameter #1 ($string) of type string is deprecated

Filename: database/DB_query_builder.php

Line Number: 1204

motoroller1983 avatar Jun 27 '22 17:06 motoroller1983

Hi!

Can you please give an example of such Query Builder usage that would trigger this error?

gxgpet avatar Jun 27 '22 19:06 gxgpet

Sure:

SELECT * FROM table ORDER BY id = 7 DESC

motoroller1983 avatar Jun 27 '22 19:06 motoroller1983

No, I mean how do you use the framework's code. If you could show your example by using QB's methods, would be really great.

gxgpet avatar Jun 27 '22 19:06 gxgpet

$BGs = $this->db->order_by("id = {$this->session->userdata['Background']['id']} DESC", NULL, FALSE)->get('table')->result_array();

motoroller1983 avatar Jun 27 '22 19:06 motoroller1983

In my project that I updated to PHP8.1, I had to check isset($var) before running various native PHP methods like htmlspecialchars($var). You could try it with trim($var): if (isset($var)){trim($var)} https://php.watch/versions/8.1/internal-func-non-nullable-null-deprecation

spitfire64 avatar Jun 30 '22 21:06 spitfire64

A PHP Error was encountered Severity: 8192

Message: trim(): Passing null to parameter #1 ($string) of type string is deprecated

Filename: libraries/Form_validation.php

Line Number: 1059

Backtrace:

File: C:\xampp\htdocs\sisurat\application\controllers\Admin\Masuk.php Line: 26 Function: run

File: C:\xampp\htdocs\sisurat\index.php Line: 315 Function: require_once

yuliaheriyana avatar Sep 08 '22 15:09 yuliaheriyana

kalau ini gimana ya ?

yuliaheriyana avatar Sep 08 '22 15:09 yuliaheriyana

kalau ini gimana ya ?

can you send your code?

mariolucasdev avatar Sep 08 '22 15:09 mariolucasdev

function save(){ $id = $this->input->post('id'); $this->form_validation->set_rules('nama_kantin','nama_kantin','required'); $this->form_validation->set_rules('telpon','telpon','required'); $this->data = [ 'nama_kantin' => $this->input->post('nama_kantin'), 'telpon' => $this->input->post('telpon'), ]; if($this->form_validation->run() == FALSE){ $this->load->view('kantin/form',$this->data); }else{ if($id == ''){ $this->makanan->insert($this->data); }else{ $this->makanan->update($id,$this->data); } redirect(base_url('kantin')); } }

Mofttach avatar Nov 19 '22 05:11 Mofttach

can you try this function save(){ $id = $this->input->post('id'); $this->form_validation->set_rules('nama_kantin','nama_kantin','required|min_length[5]'); $this->form_validation->set_rules('telpon','telpon','required'); $this->data = [ 'nama_kantin' => $this->input->post('nama_kantin')??'', 'telpon' => $this->input->post('telpon'), ]; if($this->form_validation->run() == FALSE){ $this->load->view('kantin/form',$this->data); }else{ if($id == ''){ $this->makanan->insert($this->data); }else{ $this->makanan->update($id,$this->data); } redirect(base_url('kantin')); } }

Yaser81 avatar Nov 19 '22 05:11 Yaser81

I don't understand what's with the latest comments added to this issue (or even if they are related), but regarding the initial report, you are not supposed to send the NULL value for the $direction parameter.

gxgpet avatar Mar 21 '23 23:03 gxgpet