Inline PHP Views - Can PhpStorm handle them?

Hi all.

I develop on an MVC framework that, instead of using a templating engine like Smarty, uses views with raw mixed HTML & PHP.  The guts of the code go something like this (pardon the psuedo-code):

$output->display('my-view'); // renders views/my-view.php
class Output_Helper {
  function display($view) {
    // Output helper sets up a few convenience variable functions
    $U = '__custom_url_handler';

Inside my-view.php, there might be some code like this:

<a href="<?php $U('../path/to/handle/'); ?>">Click here</a>

The net effect is that these php views act very much like Smarty .tpl files, but without the overhead required of loading the Smart library, compilation, etc.  In fact, it's more or less exactly the same process that occurs once a Smarty template has been compiled.  The scope is isolated; everything works well.  Even if some rogue view decides to override one of the convenience variables, subsequent views are unaffected, because the scope and variables are reset every time.

However, PhpStorm gets angry with these files.

Because convenience variables like $U are defined outside the include, PhpStorm doesn't know what type or value $U is.  Moreover, I've found that if $U or $u is rewritten in one view (as I have encountered in a couple of projects written in this framework), PhpStorm seems to remember this assignment across all files--even though these files would never share the same scope.



$u = new Model_User();


$U('../path/'); // PhpStorm throws the error: "Function name must be callable - a string, Closure or class implementing __invoke, currently Model_User"

This error seems to be generated at the "syntax" level, not the code inspection level, so I can't find any means to control it.  Is there a way to change this behavior, or to get PhpStorm to interpret the scope of these files differently?  I would simply ignore this behavior if it were a warning or soft warning, but being an error-level highlight, kinda makes it hard to ignore.

Please sign in to leave a comment.