【发布时间】:2016-06-25 04:19:38
【问题描述】:
我正在尝试使用一个名为 tcpdf-extension 的 php 库。该库使用namespaces 和'use' 命令。我的其余代码没有。我对namespaces 很陌生,不知道如何使用它们。
如果我包含该库,我会遇到 php 无法找到其他包含/必需文件的问题。例如:'PHP Fatal error: require_once(): Failed opening required <filepath>(include_path='.;C:\php\pear') in <filepath> on line 29'
另一个问题是我以前工作的一些网站页面只是挂起而没有任何错误消息。如果我删除库的包含,一切都会恢复正常。
如果我在与其余代码不同的页面中使用该库,则没有问题,但只要将它包含在任何其他页面中,它就会失败。
为什么会发生这种情况,我可以做些什么来解决它?
更新:包含库的示例:
require_once ('tcpdf/Extension/Helper.php');
require_once ('tcpdf/Extension/Table/Table.php');
require_once ('tcpdf/Extension/Table/Cell.php');
require_once ('tcpdf/Extension/Table/Row.php');
require_once ('tcpdf/Extension/Table/TableConverter.php');
require_once ('tcpdf\Extension\Attribute\AbstractAttribute.php');
require_once ('tcpdf\Extension\Attribute\BackgroundAttribute.php');
require_once ('tcpdf\Extension\Attribute\BackgroundFormatterOptions.php');
如果注释掉,问题就消失了,但我需要使用这个库。
这是 Table.php 中的一个部分:
<?php
namespace Tcpdf\Extension\Table;
class Table{
...
这是 Cell.php 的一部分:
namespace Tcpdf\Extension\Table;
use Tcpdf\Extension\Attribute\BackgroundAttribute;
class Cell
{
...
我的猜测是 use 和/或 namespace 命令与它有关,因为这是这个库与我使用的其他库没有任何问题的唯一不同之处。我还尝试注释掉使用命令,这使得库外的代码可以正常工作,但它会使库无法工作。也许在我包含这个库之后,我需要给出另一个“使用”命令来为我的其余代码返回正确的命名空间。但是,由于我从未为代码设置命名空间,所以我不知道 use 命令会是什么。
这是有问题的图书馆: https://github.com/naitsirch/tcpdf-extension
另一个可能相关的细节:我的大部分代码都是程序风格。我经常使用类,但大部分(非常大的)代码库根本不在类中。如果都在类中,我相信我可以为每个类添加 use 语句,但事实并非如此。
【问题讨论】:
-
你的代码呢,伙计?
-
“我遇到问题”是什么意思?您的错误日志文件中有哪些条目?
-
'PHP Fatal error: require_once(): Failed opening required <filepath>(include_path='.;C:\php\pear') in <filepath> on line 29' -
另一个问题是有些页面只是挂起而没有任何错误消息。
-
这个项目中有大量的代码。我不知道哪些部分与这个问题有关。 10,000 行代码中,您希望我发布哪一部分?
标签: php namespaces tcpdf