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 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)