PHP Netbeans 中的未知函数 - 如何抑制? [英] Unknown function in PHP Netbeans - how to suppress?
问题描述
由于我在 localhost
上开发但部署在其他地方,并且由于我不想强制我的网站位于 Windows 分区的根目录(当前为 F:\web_dev\htdocs)下,代码如下:
Since I develop on localhost
but deploy elsewhere, and since I don't want to have to force my sites to be under a Windows partition's root directory (currently F:\web_dev\htdocs), code like this:
require_once($_SERVER['DOCUMENT_ROOT'] . '/projXY/database/database_common.php');
OdbcExec($sql); // defined in the file above
导致 Netbeans 发出警告:未知函数".
causes Netbeans to issue a "Warning: unknown function".
现在,我可以通过使用如下目录结构来解决这个问题:
Now, I could get round this by using a directory structure like :
F:\project_1
F:\project_2
代替
F:\web_dev_htdocs\project_1
F:\web_dev_htdocs\project_2
然后使用
require_once('/database/database_common.php');
但是这对最终用户安装我的网站的位置施加了限制.
BUT that imposes constraints on where the end-user an install my site.
目前最简单的方法是告诉 NetBeans 哪个本地目录对应于 $_SERVER['DOCUMENT_ROOT']
,但我找不到相应的配置选项.我确定这是一个常见问题.有什么建议吗?
Simplest by far would be to tell NetBeans which local directory corresponds to $_SERVER['DOCUMENT_ROOT']
, but I can't find a configuration option for that. I am sure this is a common problem. Any suggestions?
更新:NetbBeans v7.0.1
Update: NetbBeans v7.0.1
推荐答案
只需将 /path/to/projXY/database/
目录添加到项目的包含路径中.Netbeans 然后会在那里提取文件并将它们用作代码引用.
Simply add the /path/to/projXY/database/
directory to your project's include path. Netbeans will then pick up the files there and use them as code references.
http://netbeans.org/kb/docs/php/project-setup.html#phpIncludePath
依赖 $_SERVER['DOCUMENT_ROOT']
通常是个坏主意.一方面,它消除了通过控制台/命令行运行部分应用程序的能力.
Relying on $_SERVER['DOCUMENT_ROOT']
is generally a bad idea. For one, it eliminates the ability to run parts of your application via the console / command line.
您应该改为使用可配置的绝对路径来共享库,或者按照 布兰登的回答 并使用来自 __DIR__
(PHP 5.3) 或 dirname(__FILE__)
You should instead either use configurable, absolute paths to shared libraries or do as in Brandon's answer and use a relative path from __DIR__
(PHP 5.3) or dirname(__FILE__)
这篇关于PHP Netbeans 中的未知函数 - 如何抑制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!