Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expose "use" classes to Included file

Example:

namespace Somenamespace;    
use Somenamespace\Someclass;
use Somenamespace\otherclass;


class Template{

  public function display($templ){
    load_template($templ);
  }

}


function load_template($file){
  unset($file);
  require func_get_arg(0);
}

$template = new Template();
$template->display('file.php');

Now I want to access "Someclass" in file.php, without having to declare it first in the "use" statement. eg. someclass::dostuff(); (without the namespace)

Is it possible?

like image 340
Alex Avatar asked Dec 28 '25 16:12

Alex


1 Answers

Simply: no. See note bellow the example http://www.php.net/manual/en/language.namespaces.importing.php#example-247

Importing rules are per file basis, meaning included files will NOT inherit the parent file's importing rules.

like image 163
dev-null-dweller Avatar answered Dec 31 '25 19:12

dev-null-dweller