Let $R$ be a commutative ring with identity. Let $\phi:\cal J(R)\to\cal J(R)\cup\{\emptyset\}$ be a function, where $\cal J(R)$ denotes the set of all ideals of $R$. A proper ideal $Q$ of $R$ is called $\phi$-primary if whenever $a,b\in R$, $ab\in Q-\phi(Q)$ implies that either $a\in Q$ or $b\in\sqrt{Q}$. So if we take $\phi_{\emptyset}(Q)=\emptyset$ (resp., $\phi_0(Q)=0)$, a $\phi$-primary ideal is primary (resp., weakly primary). In this paper we study the properties of several generalizations of primary ideals of $R$.