PHP Soap 和命名空间。 PHP 致命错误:类“Jira\SoapClient”未找到
我们正在更新我们的代码库以使用 PHP-5.3+ 中提供的命名空间功能
以前,我们的文件都愉快地存在于 /htdocs/php 中的网络服务器上,但现在我们正在分离我们的脚本,并将我们的 PHP 库放在 /htdocs/php/ 中lib/
在 /htdocs/php/lib/ 中,我们有一个名为 Jira.php 的文件,我们为其指定了命名空间:
<?php
# Define a namespace for this library
namespace Jira;
function create_client($jira_url, $options)
{
global $client;
try
{
$client = new SoapClient($jira_url, $options);
}
catch (Exception $error)
{
echo $error -> getMessage() . "<br/><p style='color:red'> Could not connect to Jira </p>";
}
}
?>
但是,当我们尝试从 /htdocs/php 中的脚本调用此函数时,我们得到的类不是发现错误:
PHP Fatal error: Class 'Jira\SoapClient' not found
当我们尝试创建 SoapClient 对象时,这会失败。
我已经验证我已将 php-soap 包安装在 /usr/share/php/SOAP/ 中 和 php_info();显示它已启用等。
所以推测这是命名空间约定的问题。我们如何包含该类而不引发错误?
问候, ns
We are updating our codebase to use the namespace functionality provided in PHP-5.3+
Previously, our files all lived happily on the webserver in /htdocs/php but now we are separating our scripts, and putting our PHP libraries in /htdocs/php/lib/
In /htdocs/php/lib/ we have a file called Jira.php which we have given a namespace to:
<?php
# Define a namespace for this library
namespace Jira;
function create_client($jira_url, $options)
{
global $client;
try
{
$client = new SoapClient($jira_url, $options);
}
catch (Exception $error)
{
echo $error -> getMessage() . "<br/><p style='color:red'> Could not connect to Jira </p>";
}
}
?>
However, when we try and call this function from a script in /htdocs/php, we are getting the class not found error:
PHP Fatal error: Class 'Jira\SoapClient' not found
This is failing when we try creating the SoapClient object.
I have verified that I have the php-soap package installed in /usr/share/php/SOAP/
and php_info(); is showing that it is enabled etc.
So presumably this is a problem with the namespace convention. How do we include that class without it throwing an error?
Regards,
ns
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
SoapClient 可能被分配给全局命名空间。
在您的脚本中,当前命名空间是
Jira。
尝试使用:
SoapClient is probably assigned to the global namespace.
In your script the current namespace is
Jira.
Try using: