简体   繁体   中英

PHP file include stops execution

I have the following code inside the body of my index.php page:

echo "Begin <br />";
include('test.shtml');
echo "Importing dbRead.php here <br />";
include(dirname(__FILE__) . '/dbRead.php');
echo "We have included dbRead.php here <br />";

The output on the page is:

Begin
Inside test.shtml
Importing dbRead.php here

The files are all in the same directory. What's going on?

EDIT: dbRead.php is a class. It is parsed just fine by my WAMP server, but not the web server after I upload. It contains a single class with properly formed methods and a constructor.

As far as I see all the echos are executed before include(dirname(__FILE__). '/dbRead.php'); , but no echo output is visible after that. There are some possibilities, for example:

  • in dbRead.php you use for example ob_start(); (see documentation ), thus the echo is executed, but not sent to the browser,
  • you have some error that terminates the script in dbRead.php , but you have error reporting turned off (see documentation ),
  • you invoked exit (see documentation ) or die() (see documentation ) within the included file,

Based on your output the issue isn't the include s (btw, dirname(__FILE__) is unnecessary unless the file itself (index.php) is also included by another file)... the issue is you have an error in dbRead.php or it doesn't exist, or it stops further execution (with exit die etc).

Does your DIR look like:

/
/index.php
/test.shtml
/dbRead.php

?? Or are you expecting the dirname(__FILE__) to shift the directory in some way?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM