How to use the functions defined by require in php?

Source: Internet
Author: User
How does php use the function defined by require in the process to succeed ;? Php $ testyes; fna ($ test); functionfna ($ a) {& nbsp; echo $ ;}? & Gt; however, a. php ---- & lt ;? Php $ testyes; fna ($ test); require (B. php );? & Gt; how does B php use the functions defined by require below the process?
This will succeed.
$ Test = 'yes ';
Fna ($ test );
Function fna ($)
{
Echo $;
}
?>

But in this way, you cannot call
A. php
----
$ Test = 'yes ';
Fna ($ test );
Require ('B. php ');
?>

B. php
----
Function fna ($)
{
Echo $;
}
?>

1. I know that you can directly call require by putting it in front.
2. google has another solution to use the autoload mechanism.

Is there no "declaration" solution?


------ Solution --------------------
Autoload is only applicable to automatic loading of class files, but not to functions.
What does "no" declaration "mean? You all know that require is always on the front. why do you need to take a detour?
------ Solution --------------------
Use function_exists to determine whether the specified file exists.
------ Solution --------------------
"Must be defined first and then used" is one of the main arguments for criticizing PHP.
Isn't it all about php grassroots? Non-standard? You can use undeclared variables!

So php developers listened to your opinion and gave up the priority of require during compilation.
Therefore, there is no qualitative difference between require and include.

Since you all insist on "first defining and then using", why does he need to maintain flexibility? After all, php is used as a tool for you.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.