问题
As in title, in my html5 document, php script is ending too early, due to misreading -> as a closing tag. I have no idea why? I'm using Adobe Dreamweaver.
<?php
define('IN_PHPBB', true);
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
$user -> session_begin();
$auth -> acl($user = data);
$user -> setup();
?>
It's not just highlighting error, and removing spaces makes no difference. Changed session_begin() to session_start() still nothing. I can see lines
session_start(); $auth->acl($user = data); $user->setup(); ?>
on my website.
The problem was, my file was a .html file ;> Thanks for replies
回答1:
Short Version: It's not. PHP terminates at ?>
(or possibly %>
if you're using asp style tags).
Long Version: Take a look through your document, try placing various echo statements around to ensure you're exiting where you think you are. Edit the file with a plain text viewer if you can, to make sure your editor isn't hiding anything from you.
Update
Ensure that your include is performing correctly. If it's unable to find that file, or the file doesn't create the user
object, your next line will fail, and PHP will terminate.
回答2:
Yep, it's the spaces:
//replace
$user -> session_begin();
//with
$user->session_begin();
and all other places where ->
is a space.
来源:https://stackoverflow.com/questions/7894334/why-php-tag-is-closing-on-user