Suppose there's a global object called $user which refers to the currently-logged-in user.
Consider this example function:
Now suppose that I'm logged in with an admin account, but I want to call this function and have it do stuff to a different user account, for debugging purposes or whatever. Inside the function, it possible to override the global $user with a function argument?
E.g.
Consider this example function:
Code:
function example_function() {
global $user; // reference the global user object
echo $user->id;
}
Now suppose that I'm logged in with an admin account, but I want to call this function and have it do stuff to a different user account, for debugging purposes or whatever. Inside the function, it possible to override the global $user with a function argument?
E.g.
Code:
function example_function($user) { // can this argument...
global $user; // ...override this declaration?
echo $user->id;
}
if($DEBUG) {
example_function($a_different_user_than_the_admin_who_is_logged_in);
}