0

Sorry if this is a stupid question. I am currently learning PHP and using PHP with WordPress. Currently I am limiting the amount of characters comments on my WordPress site can be.

I have a function which uses the hook 'preprocess_comment' .

In the wordpress codex it says preprocess_comment takes one parameter which is an array called $commentdata.

function preprocess_comment_handler( $commentdata ) {
    //some code
    return $commentdata;
}

The function I am using gives a parameter of $comment

function nyt_preprocess_comment($comment) {
    if ( strlen( $comment['comment_content'] ) > 5000 ) {
        wp_die('Comment is too long.');
    }
    return $comment;
}

My question is do the parameters not have to have the same name? If not, how come?

Thank you

2
  • 3
    No they don't. The passed parameter's "value" is passed to the function, so the "value" of that variable is passed to the function parameter and that "value" is assigned. Commented Apr 28, 2015 at 15:42
  • Thank you for explaining that. Do you want to put it in an answer so i can accept it? Commented Apr 28, 2015 at 15:56

1 Answer 1

1

The passed parameters do not have to have the same name. The passed parameter's "value" is passed to the function, so the "value" of that variable is passed to the function parameter and that "value" is assigned and used in the function.

So in the example the value of $a which is 1 is passed to the functions and assigned to $x or $yyyy respectively:

function foo($x) {
    echo $x;
}

function bar($yyyy) {
    echo $yyyy;
}

$a = 1;
foo($a);
bar($a);
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.