MyBB Community Forums

Full Version: '$message' or '$msg' ?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm looking through a few plugins trying to learn how to write plugins for MyBB and I noticed something. In 2 seperate plugins that use the "parse_message" hook, I see two different variables used for the text of the message. Both $message and $msg are used. I can't find "$msg" anywhere in any of the core files, but the plugin that uses $msg does work, so it must be correct.

My question is, what's the difference between $message and $msg ?
The variable is passed through the argument to the function of $msg. So whatever the contents of $message of passed by the plugin hook is automatically assigned to $msg in the function argument. When you return $msg; it overwrites $message with the contents returned by the function (in this case $msg).
Uh.... English please? Toungue

Really though, I didn't understand a word of that. Could I get an example or something?

// assign some string to the variable
$some_other_var = "test";

// Pass the variable through the function. Now $some_variable = $some_other_var in the function (it's not global)
echo some_function($some_other_var);

function some_function($some_variable)
{
     // $some_variable now holds the contents from $some_other_var sent earlier
     return $some_variable;
}


does that help?
Ok, but that doesn't tell me what the difference is between $message and $msg.  Why would you use $msg instead of $message?

Does $message === $msg or is there a difference?  Like, is $message the fully parsed message that was posted and $msg is the unparsed raw content from the post form or something like that?

Ok, let me ask the question better. I think you've taken it as "what's the difference between those two variables themselves." No, what I mean to ask is what's the difference between the content of those two variables.
When you pass a variable as an argrument for a function its atomatically assigned to the variable defined in the function. Does that make sense?


Perhaps a PHP book would be better Confused

Technically there's no difference between $message and $msg if you pass $msg as the variable into the function and $message is the retrieving argument they will be the same ($message = $msg)
Ok, that explains it. Thank you Smile