【问题标题】:Object orientated php面向对象的php
【发布时间】: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?&gt;postMessage 而不是 $post-&gt;postMessage,这将在 ?&gt; 处结束代码标记并在页面中显示其余代码。跨度>
  • 你的“log.html”文件可能只是简单的,你可能需要检查一下。
  • 不知道为什么,但这段代码在我的服务器上运行良好,但在我的计算机上却完全不行。

标签: php html function object external


【解决方案1】:

刚刚测试了您的代码,它运行良好,检查是否有拼写错误或您的脚本是否具有扩展名.php。如果不是,这将导致输出按字面意思显示您的代码。

【讨论】:

    猜你喜欢
    • 2010-12-11
    • 2011-04-28
    • 2011-02-27
    • 1970-01-01
    • 2011-07-25
    • 2011-07-09
    • 1970-01-01
    • 1970-01-01
    • 2011-08-01
    相关资源
    最近更新 更多