Kalzem
Kalzem

Reputation: 7492

empty() doesn't work with codeigniter input class

This is really weird. Whenever I call something like

if(empty($this->input->post("foo")){//blabla}

The whole PHP is "down" and I get a blank page from the website (even when I don't pass through this empty(input) line).

I know this is not the right method and it is stupid, I change the code to

if(!$this->input->post("foo")){//blabla}

Better I guess ?

Seriously, how come the empty(input) breaks down the entire PHP page ? (I can't get any echo "something").

Upvotes: 0

Views: 1172

Answers (3)

xdazz
xdazz

Reputation: 160853

From the manual:

Note:

empty() only checks variables as anything else will result in a parse error. In other words, the following will not work: empty(trim($name)).

Update: From php 5.5, empty() supports expressions too.

Changelog:

5.5.0 empty() now supports expressions, rather than only variables.

Upvotes: 3

Code Prank
Code Prank

Reputation: 4250

You dont need to use empty with input class because if the post variable does not exists or contains null value input class returns false which automatically fails the if condition and your else block would work...

Upvotes: 1

deceze
deceze

Reputation: 522135

You cannot use empty with functions, and neither do you need to. empty is a special construct that only works on variables and triggers a fatal error otherwise. See The Definitive Guide To isset And empty.

Upvotes: 2

Related Questions