0

my functions have become extra strict about passing ALL of the arguments now instead of just what I need)

This used to work

function namedFunction($avar, $bvar, $cvar){
.......
}

echo namedFunction('a','b');

Now NOTHING works unless I pass

echo namedFunction('a','b','');
mark h
  • 41
  • 7
  • On your function definition simply set `... $bvar,$cvar = null){...` as a default value. I don't think this is a recent update, but it's been standard for a long time as far as I'm aware.... – Martin Apr 23 '21 at 19:11
  • 2
    You probably have a HUGE error log in PHP 7 with all the WARNINGS that this sort of lax function coding has produced..... – Martin Apr 23 '21 at 19:12
  • This was never valid code: https://3v4l.org/kPWVN but it's _extra_ invalid as of 7.1. When you are writing new code you should have `error_reporting` at a level that shows you at _least_ warnings as there is a very good chance that warnings early on will indicate the cause of a later error. Also, 7.2 EOL is coming up, get thee to at least 7.4. – Sammitch Apr 23 '21 at 20:07

1 Answers1

2

You can assign a default value to the parameter:

function myFunction( $a, $b, $c = "" )
{
  ...
}

myFunction( $a, $b );

Check your error logs from when you were doing this with PHP 7.0 - not providing a parameter that has no default value isn't valid syntax in 7.0 or 7.2 (or any other version as far as I remember).

DannyXCII
  • 888
  • 4
  • 12