With the use statement.
If static methods that's all you need. If instance methods you need a new instance of the class injected.
If straight php, lookup the require and include statements.
Take the php for beginners free course from here.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I'll try to explain my need more simply) I have several parsers, each of which has its own file with the necessary functions. When the function starts, I need to load this file with functions for it to work. How can I do this?
Let's assume a file with functions like this:
<?php
function getCategory ($catId) {
if ($catId == '123') {
return 'phones';
} else {
return 'laptops';
}
}
The method in the controller looks like this:
class ParserController extends Controller
{
public function getData($id)
{
$model = Parser::find($id);
include(Storage::disk('local')->get('parsers/functions/' . $model->id . '-' . $model->title . '.php'));
dd(getCategory('123'));
}
}
I'm getting this error. It seems to be reading the file, but I can’t use the functions from it.
ErrorException include(<?php function getCategory ($catId) { if ($catId == '123') { return 'phones'; } else { return 'laptops'; } } ): failed to open stream: No error
What am I doing wrong?
Please or to participate in this conversation.