【问题标题】:PHP: Class file in the same directory not being recognized?PHP:同一目录中的类文件无法识别?
【发布时间】:2009-06-18 17:32:29
【问题描述】:

我在同一个目录下有两个php文件:

test.tattler.php
class.tattler_stats.php

我的 test.tattler 应该创建一个我的 tattler_stats 的对象,但它给了我这个错误:

Fatal error: Class 'tattler_stats' not found in /.../test.tattler.php on line 4

test.tattler 中的代码:

<?php

include 'class.tattler_stats.php';

$tattler_test = new tattler_stats( $_REQUEST );

?>

tattler_stats 中的代码:

function __construct( $_REQUEST )
{
    $param = $_REQUEST['menu'];

    run();
}

function run()
{
    connect();
    showMenu( $parm ) ;
//rest of class...

【问题讨论】:

    标签: php class oop


    【解决方案1】:

    确保您实际上是在类文件中声明该类

    class tattler_stats {
        // class code here
    }
    

    如果您已经这样做了,请尝试更具体地指定路径:

    include(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'class.tattler_stats.php');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-10
      • 1970-01-01
      • 1970-01-01
      • 2021-05-06
      • 2021-09-28
      相关资源
      最近更新 更多