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

Randall Zepeda
Randall Zepeda
1,979 Points

null

what is the point of putting null in your parameters functions instead of just leaving it equal to nothing as it shows the same result and outputs the ELSE statement either way. example below: notice if i made parameter $swag=Null, it will still echo the same result.

<?php

function buck_zitches($game,$swag){ if($swag){echo "randy has $game and $swag";} else{echo"randys da best $game";}}

buck_zitches('skillz'); ?>

2 Answers

Hi Randall,

So the question you are asking is basically:

Is passing NULL param exactly the same as passing no param?

OR

Does PHP treat passing a NULL exactly the same as not passing anything?

Have you considered the question in the context of using the func_num_args function?

Probably not..


Anyway..I think such questions are pretty mundane,

but questions like the one you're asking make those guys over at StackOverFlow drool with anticipation.. :wink:

..they really love answering programming trivia like this,

So I let them give you their answers here:

http://stackoverflow.com/questions/4573590/is-passing-null-param-exactly-the-same-as-passing-no-param

Randall Zepeda
Randall Zepeda
1,979 Points

lol thanks and naa ill check func_num_args out