Questions about require in PHP
1. How do I use require in PHP to include all the files in a folder?
Require ("./folder/*") is not possible, PHP can not be like the Java include the same flexible and convenient?
Can't I recognize the name in a regular? Pattern recognition?
2. Not require the same class two times?
File name:A_Dao.class.php
Function:contain Basic operations of A.class
A_Dao.class.php
Require ("DBConnection.class.php");
...
...
...
?>
Another file:B_Dao.class.php
Function:contain Basic operations of B.class
B_Dao.class.php
Require ("DBConnection.class.php");
...
...
...
?>
A and B.class is entities as abstracted from conceptions.
ServiceA.class.php
Require ("./dao/a_dao.class.php");
Require ("./dao/b_dao.class.php");
...
...
...
?>
Run ServiceA.class.php
"Fatal Error:cannot Redeclare class DBConnection in C:\Program files\apache software foundation\apache2.2\htdocs\ application\dao\dbconnection.class.php on line 3 "
What ' s wrong?
Why can't I repeat require the same (DBConnection.class.php)?
Does the compiler not always handle it (like Java)?
------Solution--------------------
Why do you want to require (*)?
Require will insert all the target files into the current file. If * is allowed, all files in the directory will be inserted so that the file is super large.
Second question:
Require_once
There are no duplicates of the include same file that are not allowed in C + +.
------Solution--------------------
PHP's include and C languages are similar, each execution page will include once,
If this is supported, I think, it will seriously affect efficiency.
Unlike Java's import java.io.*; After compilation, only imports are used to get the library, without affecting the. Class size
------Solution--------------------
Require ("./folder/*") can add to the burden on the server, because the server is unable to withstand every request that the Web server receives if it is loaded as a file below all folder.
PHP is only allowed to be included once, you can use require_once to avoid repeating require.
------Solution--------------------
You can use AutoLoad.
------Solution--------------------
Require_once ()
------Solution--------------------
1. In comparison, Java can be said to be "symbol-level" of the inclusion, and PHP, regardless of include/include_once/require/require_once, are "file-level" of the inclusion, so PHP does not support wildcard characters are also understandable. If you want to "include all program files in a folder" effect, you can use Scandir () or a similar way to do all the history of inclusion, and not complex. As long as it is "needed", it doesn't matter how inefficient it is.
2. It's good to use the require_once. 1 floor, 3 floor brothers said there are inaccurate places. Php/c/c++ are allowed to be included multiple times. PHP repeatedly contains errors, just because function and class can not be "repeated definition."
————————————————————————————————
[Img=http://csdnimg.cn/bbs/m/i/red_1.gif] medal [/img][img=http://csdnimg.cn/bbs/m/i/yellow_1.gif] medal [/img][img=http ://csdnimg.cn/bbs/m/i/blue_1.gif] medal [/IMG] medal ah ... When can I get these ...?
————————————————————————————————
Based on the plugin extension function provided by CSDN forum, I have made a signature file tool to share with you, welcome technical exchange:)