【发布时间】:2014-08-25 01:10:42
【问题描述】:
我刚刚开始学习面向对象的 php,但我遇到了我怀疑是一个非常微不足道的问题。我有两个 .php 文件,post.php 和 testPost.php,如下所示:
//post.php
<?php
class fileWrite{
public function postMessage($logId, $text, $username){
//If the original login form was not used then this would not be set
date_default_timezone_set('Europe/London');
$fp = fopen($logId, 'a');
fwrite($fp, $text);
fclose($fp);
}
}
?>
//testPost.php
<?php
include 'post.php';
$post = new fileWrite;
$post->postMessage("log.html", "test", "username");
?>
当我运行 testPost.php 时,输出如下: postMessage("log.html", "test", "username"); ?>
任何帮助将不胜感激。
【问题讨论】:
-
在文件中查找拼写错误,例如
$post?>postMessage而不是$post->postMessage,这将在?>处结束代码标记并在页面中显示其余代码。跨度> -
你的“log.html”文件可能只是简单的,你可能需要检查一下。
-
不知道为什么,但这段代码在我的服务器上运行良好,但在我的计算机上却完全不行。
标签: php html function object external