I have observed this as well. I am wondering if the code snippet sends an invitation, and the user is not added a member until the user confirms. That makes sense in some cases but not all.
In my case, membership is granted upon payment of a subscription. This requires that I be able to add a member at the administrative level. An email asking for confirmation is not required and may be viewed by some as unnecessary complication.
How does the administrator grant membership with immediate effect?