dprh34164 2013-06-16 21:24
浏览 76
已采纳

PHP名称空间常量未定义

I'm relatively new to PHP, and I'm trying to unit test some code within a namespace. unfortunately constant definition in a config file is giving me issues. Here is the relevant code.

directory structure is:

APITest
config.php
-/logging
-/test/logging

code of config.php:

<?php
namespace APITest;
define('BASE_DIR', pathinfo(__FILE__, PATHINFO_DIRNAME));

code of APITest/test/logging/TestLogItem:

namespace APITest\test\logging;
require_once( BASE_DIR . '/logging/LogItem.php');   
class TestLogItem extends PHPUnit_Framework_TestCase {

public function testLogItemCreationSuccess(){
    code
}

public function testLogItemCreationException(){
    code
}

public function testGetLogEntry(){
    code
}

error message is: PHP Notice: Use of undefined constant BASE_DIR - assumed 'BASE_DIR' in /var/test/APITest/test/logging/TestLogItem.php on line 6 PHP Warning: require_once(BASE_DIR/logging/LogItem.php): failed to open stream: No such file or directory in /var/test/APITest/test/logging/TestLogItem.php on line 6 PHP Fatal error: require_once(): Failed opening required 'BASE_DIR/logging/LogItem.php' (include_path='.:/usr/share/php:/usr/share/pear') in /var/test/APITest/test/logging/TestLogItem.php on line 6

  • 写回答

1条回答 默认 最新

  • douchun1859 2013-06-16 21:28
    关注

    You need to include config.php in the file.

    It doesn't look like you are including the file anywhere, so as far as PHP is concerned the constant isn't defined.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试