Software Engineering in WordPress and Musings on the Deep Life

The Difference Between Parameters and Arguments

When reading the documentation, reading technical articles, or dealing with anything programming related you’re going to come across both parameters and arguments.

Sometimes, people will use these phrases interchangeably. For what it’s worth, I think that’s okay. People know what the speaker or author is referring to when they are using these terms.

But there is a difference between the two. So if you find yourself in a situation – maybe an interview or a setting that requires a bit more precision – here’s the difference.

Parameters and Arguments

First, let’s take an example from the WordPress code reference for a given function and let’s look at its parameter list.

Parameters and Arguments

For add_user_meta, the parameters are:

  • `$user_id`
  • `$meta_key`
  • `$meta_value`
  • And an optional `$unique` value

So what distinguishes these from being called arguments?

Parameters are the values the function accepts. Arguments are the values passed to the function.

That’s all. So when you’re talking about a function and the allowed values, those are its parameters. When you’re writing code, and you’re passing specific values into a function, those are arguments.

8 Comments

  1. Ben Meredith

    I’d be helped by also seeing a core function with arguments passed to the function, for reference.

    I think I get it, but I thought I’d toss that out there.

    Thanks!

  2. Philip

    //use: some_function( $param1, $param2, $param3 );

    //arguments with values

    $arg1 = ‘value 1’; //string

    $arg2 = 2; //int

    $arg3 = true; //boolean

    //arguments passed to function through its parameters

    some_function( $arg1, $arg2, $arg3 );

  3. Ahmad Awais

    I had a big debate about this one with one of my team members.

    BTW the first parameter is $user_id not $add_user_meta.

    Cheers

  4. Carl Alexander

    I have to constantly check myself with these two when I write an article. It’s so easy to use them interchangeably! I find it’s also the case when using class vs object.

    • Tom

      It’s funny how the simplest things ends up being one of those things on which we have to keep double-checking ourselves.

  5. Amen Moja Ra

    Hey this is great. I know about 12 years ago it took me a while to understand both of these concepts. For new developers this will help them tremendously!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

© 2023 Tom McFarlin

Theme by Anders NorenUp ↑