mazlix mazlix - 2 months ago 10x
PHP Question

Undefined variable: errors from empty 3rd uri params (code igniter)

I have many controllers with functions like

function search($person) {
if empty($person) {
else {

I wasn't getting Undefined variable errors before, but now i do (if i go to .../search/) without passing a $person. I found i can fix this by doing
function search($person = null)
but i was wondering if there is a "better" way. I am also curious why i wasn't getting errors before (on localhost) but am now.. (on godaddy).



I wouldn't provide a default value for the argument in this case, function search($person) is how the function should be declared if $person is indeed a required argument. You want this to throw a warning so you can quickly see what's wrong during development.

In production, you simply switch off error reporting/error display.