0

How do I prevent the default first parameters from being overwritten, when second has to be change? I expect the output "SecretPassword", not NULL

<?php

  myFunc(NULL,true); //echo NULL not:"SecretPassword"
    
  function myFunc($param1='SecretPassword',$param2=false){
      echo $param1;
  }
?>
dazzafact
  • 2,570
  • 3
  • 30
  • 49
  • 1
    Not possible. https://stackoverflow.com/questions/1066625/how-would-i-skip-optional-arguments-in-a-function-call – IT goldman Jul 30 '22 at 20:12
  • 1
    If you are using PHP 8, you CAN do that using named arguments, they were done for that exact purpose. – Lothric Jul 31 '22 at 02:33

1 Answers1

1

you can't, as far as I understand. you would want to write the arguments in reverse order in the function's argument list, so that you can simply leave off the second argument.

dqhendricks
  • 19,030
  • 11
  • 50
  • 83