You want to define your own namespace for keys and separate key definition from usage.
\documentclass{article}
\usepackage{tikz}
\pgfkeys{/lyl/mycolorbox/.cd, % define your own space
color/.store in=\mycolorboxcolor,
text/.store in=\mycolorboxtext,
color=red!40,
text=some text,
}
\newcommand{\mycolorbox}[1][]{%
\begingroup
\pgfkeys{/lyl/mycolorbox/.cd,#1}%
\colorbox{\mycolorboxcolor}{\mycolorboxtext}%
\endgroup
}
\begin{document}
\mycolorbox[color=blue!20]
\mycolorbox[text=This is a practice.]
\mycolorbox[color=blue!20, text=This is a practice.]
\end{document}
The expl3 version:
\documentclass{article}
\usepackage{xcolor}
\ExplSyntaxOn
\keys_define:nn { lyl/mycolorbox }
{
color .tl_set:N = \l__lyl_mycolorbox_color_tl,
text .tl_set:N = \l__lyl_mycolorbox_text_tl,
color .initial:n = red!40,
text .initial:n = some~text,
}
\NewDocumentCommand{\mycolorbox}{O{}}
{
\group_begin:
\keys_set:nn { lyl/mycolorbox } { #1 }
\colorbox{\l__lyl_mycolorbox_color_tl}{\l__lyl_mycolorbox_text_tl}
\group_end:
}
\ExplSyntaxOff
\begin{document}
\mycolorbox[color=blue!20]
\mycolorbox[text=This is a practice.]
\mycolorbox[color=blue!20, text=This is a practice.]
\end{document}
