Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.