1

when and where I should keep the Parameters Null or FALSE? for stance here is a function... and what this function will do when i called it or how can i call it?

<?php 
 function Show_result($id=Null, $name=FALSE){
     //whatever i want code goes here
  }
 ?>
Next Door
  • 69
  • 1
  • 1
  • 9
  • 1
    I usually use defaults on each function declaration just so I can call the function without having to pass parameters. Setting them to null or false, gives me the ability to make sure there are arguments passed. – Scott Miller Jun 10 '17 at 15:57

1 Answers1

2

In this declaration you set default values so you can call this function without passing parameters.

This could be useful if you don't want to pass the same parameters most of the times but still be able to pass specific ones in other cases.

For example, a function like this :

function log($message, $tag = null) {
    if ($tag == null)
        $tag = "info";
    echo $tag . ": " . $message;
}

This function can be called two ways:

log("text")

or

log("text", "error")

The first call will print

info: text

The second will print

error: text
Christian Ascone
  • 1,117
  • 8
  • 14