Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP PHP Functions Introducing Functions PHP Function Default Arguments

2:21 find discrepancy, great('Mike'); will not echo Hi,Mike. It will echo Hello,Mike. Confusing. Look at code provided


function greet($name = 'friend', 
               $time_of_day = Null){
    echo "Hi, $name, good $time_of_day";
  } else { 
     echo "Hello, $name";

greet("Mike", "morning");


2 Answers

Yay! Problem solved. It's a little one for Hampton Paulk :-)

Hey Paul,

The if-statement there checks to see if $time_of_day is not a falsey value such as null. $time_of_day is set to null by default, so when you don't set $time_of_day to an explicit value, it will take the initial value of null and the else statement will execute.

What you said is correct. And thus, in the video the msg printed is Hi, Mike, but if you look closely there is no "Hi" in the else statement, yet video clearly states "Hi" instead of "Hello", it's a minor error but had me wondering for a minute.


Ah I see what you're saying after watching the video! Apologies! You should tag the instructor here so they can see this.