Reputation: 2660
I have a problem. I have made a form where a logged in user can signup to be a photographer. This works all great. On that page I check if the user isn't already a photographer by seeing if the photographer object is empty.
Like this:
if(!empty($this->user->oPhotographer)){
$this->doRedirect('alreadyapplied');
}
Now when I do a var_dump
on !empty($this->user->oPhotographer)
it returns bool(false)
. It shouldn't return this, it should return true because I'm testing with a user that has a filled photographer object.
Now the strange thing :
echo '<pre>'.var_dump(!empty($this->user->oPhotographer)).'</pre>';
if(!empty($this->user->oPhotographer)){
$this->doRedirect('alreadyapplied');
}
echo '<pre>';
var_dump(!empty($this->user->oPhotographer));
print_r($this->user->oPhotographer);
echo '</pre>';
This piece of code should redirect to the proper page when the object is not empty. The var_dump still gives false, though it doesn't redirect. This is the code output:
bool(false)
bool(false)
photographer Object
(
[table] => photographer
[data] =>
[className] =>
[arFields] => Array
(
[id] => id
[country] => country
[dateofbirth] => dateofbirth
[street] => street
[city] => city
[about] => about
[dateapplied] => dateapplied
[user_id] => user_id
[phone] => phone
[zip] => zip
)
[id] => 1
[country] => ...
[dateofbirth] => ...
[street] => ...
[city] => ...
[about] =>
[dateapplied] => 2013-04-28 19:41:08
[user_id] => 15
[phone] => ...
[zip] => ...
)
How can it return false when the photographer is actually not empty?
Upvotes: 0
Views: 2140
Reputation: 771
You should have used "isset", not "empty". The reasons are pretty clear. For more: http://php.net/manual/en/function.isset.php
Upvotes: 1