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;
  }
?>
2
  • 1
    Not possible. stackoverflow.com/questions/1066625/… Commented Jul 30, 2022 at 20:12
  • 1
    If you are using PHP 8, you CAN do that using named arguments, they were done for that exact purpose. Commented Jul 31, 2022 at 2:33

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.