Difference between include() and $this->inc();

Permalink 2 users found helpful
Hey all, can anyone explain what the difference between using
include('path/to/file.php');

and using
$this->inc('path/to/file.php');


I thought I read in the docs that $this->inc(); is the preferred way to include files in c5, however, I just had trouble including a php file in my header.php file and when I tried include() it worked. I can't find much online so I figured I'd ask the pointed question.

MrNiceGaius
View Replies: View Best Answer
andrew replied on at Permalink Best Answer Reply
andrew
$this->inc() tries to look in the correct override locations for files. Meaning that if you're building a block, if you use $this->inc() to include a file from that block's directory, you can override block files, etc.. and $this->inc() will first look in the override location, then the core block location, or the package directory (if the block is part of a package.)

Same way with $this->inc() in a theme's directory. Generally though, if used from within a theme, $this->inc() starts with the theme's current directory, and if used from within a block, it starts with the block's directory. This won't work that great if you want to hard-code an include to a particular file in the filesystem. If that's the case I'd suggest storing it in the libraries folder and using Loader::library('file'); to load it, or something like that.