But right now, the contact page is broken because get_pets() has a required
argument, and we’re not passing it anything. But what should we pass here?
1000? 1 million? We really want no limit, but that’s not possible right
now.

Next, add an if statement in get_pets(). Let’s only add the limit
if the $limit variable is set to something other than zero. We can do
this by first creating a $query variable. Then, if we have a limit, add
a little bit more to the new variable:

Whenever we have an if statement, we always pass it a boolean:
either a variable or little bit of code that equates to true or false.
When we use the != operator, PHP compares the values and feeds either true
or false to the if statement. That’s old news for us.

But let’s try something. What if we just put the $limit variable in
the if statement:

// lib/functions.php// ...if($limit){$query=$query.' LIMIT '.$limit;}

So $limit isn’t a boolean: it’s either the number 3 or 0, depending on
who’s calling it. So will this work? Will we get an error?

Refresh the contact page. No error - and it shows 4 pets. Now go to the homepage.
We see 3 pets. Things are still working!

So you can pass something other than true or false to an if
statement. And when you do, PHP looks at what’s there and tries to figure
out if it looks and smells more like true or more like false.

For example, empty things like an empty string or the number zero becomes
false. Everything else becomes true.

Value

Equates to

0

false

empty string

false

empty array

false

null

false

false

false

5

true

foo

true

array(5, 10)

true

-25

true

true

true

Even a negative number or a string that has only spaces in it becomes true,
because these aren’t really empty. So when we pass 0 for the $limit
argument, it looks like false and doesn’t enter the if statement.

Let’s change the 0 default value to null. null is the value that
is equal to “nothing”, and I used it earlier as my database password, since
my MySQL server doesn’t have a password.

Both 0 and null will look like false in the if statement, so the
code will act the same. Since null means nothing, it just feels a little
bit better to use it as the default value for an optional argument.

By the way, the name and arguments to a function are called the “signature”.
When you hear people talking about a function’s signature, it’s just a
smart-sounding way to refer to the arguments that function has and also the
value it returns. So now you’ll sound even smarter when talking with your
cool new programmer friends.