PHP Functions – Order of Arguments Matters

I had multiple optional arguments to a function and I was trying to bypass an argument that I didn’t need (which was in the middle). So I invoked the function with explicitly loading the optional argument that I needed but now I understood that PHP doesn’t like it. PHP will only take in arguments in order so unfortunately you’ll have to list all arguments in case you would like to miss any.

// Function definition:
function file_add($filePath, $fileName, $folderId = NULL, &$log = NULL) {

// This will NOT work:
file_add($tmp_file, $fileName, $log = $log);

// This will work:
file_add($tmp_file, $fileName, $folderId = NULL, $log = $log);
Posted in PHP

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s