bcit-ci / CodeIgniter

Open Source PHP Framework (originally from EllisLab)
https://codeigniter.com/
MIT License
18.27k stars 7.6k forks source link

trim(): Passing null to parameter #1 #6146

Closed motoroller1983 closed 1 year ago

motoroller1983 commented 2 years ago

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

gxgpet commented 2 years ago

Hi!

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

motoroller1983 commented 2 years ago

Sure:

SELECT * FROM table ORDER BY id = 7 DESC

gxgpet commented 2 years ago

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.

motoroller1983 commented 2 years ago

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

spitfire64 commented 2 years ago

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

yuliaheriyana commented 2 years ago

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 commented 2 years ago

kalau ini gimana ya ?

mariolucasdev commented 2 years ago

kalau ini gimana ya ?

can you send your code?

Mofttach commented 2 years ago

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')); } }

Yaser81 commented 2 years ago

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')); } }

gxgpet commented 1 year ago

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.