Home >Backend Development >PHP Problem >What is the way to call functions in other files in PHP

What is the way to call functions in other files in PHP

醉折花枝作酒筹
醉折花枝作酒筹forward
2021-06-24 15:41:514055browse

In PHP, sometimes you need to call functions in other files. The editor will introduce to you how to call functions in other files in PHP. Friends who need it can take a look at it for reference.

What is the way to call functions in other files in PHP

Most of the time you only need require_once

require, include, require_once, include_once is dazzling, why can an import in python solve the problem? Has it become so complicated in php?

include

include The most amazing thing is that you can introduce a remote php file, that is, include a URL address. I asked myself, what is the original intention of this design? Is it used to dynamically update configuration files? Isn't it better to use json interface?

include_once

Why do we need include_once when we have include? I can't understand the world of PHP at all. . . The problem with

include is that if the same file is included twice, it will cause the functions in the file to be redefined twice, and an error will be reported. this. . . When designing, just default include to include_once. Why keep include? It must be because I read too little.

require

The difference between require and include is that if the included php file reports an error, the current script can continue to execute, because this is only a warning level;

If the require php file reports an error, the current script will also report an error and stop running.

What is the difference between using include/require in a function and using it outside the function?

I often see other people’s code using include/require in functions, and I always find it inexplicable. Why can’t it be introduced at the head of the file like Python to make it easier to read?

List the effects of using include/require in a function

  • Make the scope of introduced variables limited to the current function

  • I haven’t thought of other benefits yet

Recommended learning: php video tutorial

The above is the detailed content of What is the way to call functions in other files in PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:sunzhongwei.com. If there is any infringement, please contact admin@php.cn delete