Omnicompletion will only work if the tag file contains both the class definition, and the variable declaration.
Straightforward solution
In general that means that you will need to save and (re)generate the tags file after the class Blog { ... }
and $blog = new Blog();
parts, but before trying $blog->
<C-X><C-O>
.
This is because the PHP omni-complete function will look for the class declaration of the $blog
variable in the tags file.
(BTW if you have opened the tags file in a buffer, reload it after regenerating it.)
Alternative
The vim documentation (:help ft-php-omni
) also defines a way which doesn't require the variable to be indexed in the tags file, but uses instead a specific comment on the preceding line:
/* @var $myVar myClass */
$myVar->
However, the class definition still does need to be in the tag file, and the comment is needed every time you want to use omni-complete. So typing away in a new PHP file still won't give you nice omni-completion :(
Just a thought
Maybe it is possible to generate on-the-fly a temporary tags file (like the taglist plugin) of just the unsaved buffer, and allow omni-complete to use it too?? I'm not a great vim hacker though...