Question about require in PHP 1. how does one use require in PHP to contain all files in a folder?
Require ("./folder/*") is not feasible. isn't it as flexible and convenient as include in Java in PHP?
Cannot I recognize the name in regular expressions? Pattern recognition?
2. Do not use require for the same class twice?
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 are 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 the same require (DBConnection. class. php )?
Will the compiler not always perform dynamic processing (like Java )?
Reply to discussion (solution)
Why does it require?
Require inserts all the target files into the current file. If * is allowed, all files in the directory will be inserted, so that the file will be super large.
Second question:
Require_once
C/C ++ does not allow repeated include of the same file.
Php's include is similar to the C language, and every execution page will include,
If this option is supported, I think it will seriously affect the efficiency.
Unlike the java import java. io. *; after compilation, only the library is imported for use and the. class size is not affected.
Require (". /folder/* ") will increase the burden on the server, because if the Web server loads all the files under the folder, the server will not be able to withstand each request.
Php can contain only once. you can use require_once to avoid repeated require.
That is to say, PHP will not automatically optimize it.
However, I write a corresponding data manipulation class for each object.
In this way, I need to process all the entity objects in a business and perform the insert and select operations on the database.
There are 14 object objects and 14 DAO classes.
I used to use java, and the Structs framework is layered like this.
However, I now use music videos.
Folders:
Entities: contain all the entity classes
Dao: contain all the database access objects according to every entity
Service: use dao and entitises to complete tasks
I used PHP for the first time. I don't know how PHP is systematically layered? How to design it?
Http://blog.csdn.net/tyjhField
I wrote a question in my blog. if you are interested, I can help and discuss it.
You can use Autoload
Require_once ()
1. in comparison, Java can be said to be a "symbol-level" inclusion. in PHP, no matter include/include_once/require/require_once, it is a "file-level" inclusion. therefore, PHP does not support wildcards. If you want to "include all program files in a folder", you can use scandir () or similar methods to traverse and include files. As long as it is "needed", there is no efficiency or inefficiency.
2. use require_once. What the brothers on the first and third floors say is inaccurate. PHP/C ++ can be contained multiple times. Errors are often reported during repeated inclusion in PHP, because the function and class cannot be "repeatedly defined.
????????????????????????????????
[Img = Beijing ...... When can I get these ......
????????????????????????????????
Based on the plug-in extension function provided by the CSDN forum, I have made a signing tool and shared it with you. we welcome Technical Exchange :)
I also don't know how to use the require and include. Which of the following eldest brother can help me integrate wordpress with Taobao? for help, visit www.nygjp.cn.
Do not understand, do not understand, please explain...