Home  >  Article  >  Backend Development  >  The difference between include and require in PHP, phpincluderequire_PHP tutorial

The difference between include and require in PHP, phpincluderequire_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 09:44:30970browse

The difference between include and require in PHP, phpincluderequire

The difference between include and require. In fact, there is not much difference between the two. If the file to be included does not exist, include will prompt a notice , and then continue to execute the following statement, require prompts a fatal error and exits.

According to the test, under the win32 platform, they are included first and then executed, so it is best not to have include or require statements in the included files, which will cause directory confusion.

Maybe the situation is different under *nux, but I haven’t tested it yet. If you do not want a file to be included multiple times, you can use include_once or require_once## to read and write document data:

<span> 1</span> <span>function</span> r(<span>$file_name</span><span>) {
</span><span> 2</span> <span>$filenum</span>=@<span>fopen</span>(<span>$file_name</span>,"r"<span>);
</span><span> 3</span> @<span>flock</span>(<span>$filenum</span>,<span>LOCK_SH);
</span><span> 4</span> <span>$file_data</span>=@<span>fread</span>(<span>$filenum</span>,<span>filesize</span>(<span>$file_name</span><span>));
</span><span> 5</span> @<span>fclose</span>(<span>$filenum</span><span>);
</span><span> 6</span> <span>return</span> <span>$file_data</span><span>;
</span><span> 7</span> <span>}
</span><span> 8</span> <span>function</span> w(<span>$file_name</span>,<span>$data</span>,<span>$method</span>="w"<span>){
</span><span> 9</span> <span>$filenum</span>=@<span>fopen</span>(<span>$file_name</span>,<span>$method</span><span>);
</span><span>10</span> <span>flock</span>(<span>$filenum</span>,<span>LOCK_EX);
</span><span>11</span> <span>$file_data</span>=<span>fwrite</span>(<span>$filenum</span>,<span>$data</span><span>);
</span><span>12</span> <span>fclose</span>(<span>$filenum</span><span>);
</span><span>13</span> <span>return</span> <span>$file_data</span><span>;
</span><span>14</span> }



www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1048763.htmlTechArticleThe difference between include and require in PHP, the difference between phpincluderequire include and require, in fact there is not much difference between the two. If the file to be included does not exist, include prompts notice, and then...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn