0

As I am updating my script, there is some issues appearing I don't know if because of new php version or it was there all along but I haven't noticed yet. Here is one generic example that got me a lot of troubles:

function doSomething(arg1, arg2="test", arg3="error") { ... }
// so I did run some tests...
doSomething("Hi"); arg1, arg2, arg3 will be "Hi", "test", "error"
doSomething("Hi", "again"); arg1, arg2, arg3 will be "Hi", "again", "error"
doSomething("Hi", NULL, "no error"); arg1, arg2, arg3 will be "Hi", NULL, "noerror"
doSomething("Hi", FALSE, "no error"); arg1, arg2, arg3 will be "Hi", FALSE, "noerror"

The default value is only passed if I leave the argument empty at all. But if I wish to leave arg2 empty to get the default? Is there some keyword for this or some workaround?

Gustavo
  • 1,673
  • 4
  • 24
  • 39
  • 2
    https://stackoverflow.com/a/64997399/5947043 – ADyson Aug 20 '21 at 21:58
  • Thought I am 11 years late! So PHP 8 has a solution, until PHP 7 there is no workaround but to define diferently de function itself. I am wondering if my question is duplicated or is complementing the old one... – Gustavo Aug 21 '21 at 21:54
  • I'd say it's pretty much an exact duplicate. – ADyson Aug 21 '21 at 21:57

0 Answers0