F
F
flafy42017-02-18 21:19:20
PHP
flafy4, 2017-02-18 21:19:20

How to use functions of another file in PHP?

There are 2 files. For example file.php and file1.php. There is a "getPages" function in file.php. How can I use this function in file1.php without using include and include_once?
I heard people do it through namespace... Or something like that.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
W
Wexter, 2017-02-18
@Wexter

require / require_once, you can get especially perverted by getting it through file_get_contents, tear out the function with regexp and declare it through eval, but why?

A
Anton Shamanov, 2017-02-18
@SilenceOfWinter

with functions in any way (at least until 5.6 which I use), and for classes you can make autoloading How to use namespace autoloading of php classes correctly?

I
Ivan Koryukov, 2017-02-19
@MadridianFox

If you don't have classes, then you can't do without include.
But even when your functions are class methods, and autoload is configured, then include is also done, only implicitly.
Therefore, it does not work at all without include.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question