php - 由于命名空间,全局 "Call to undefined function"函数的 "curl_init"错误

标签 php function namespaces

我使用这样的东西:

namespace Lorem ;

class Ipsum {
    function foo ($url) {
        $c = curl_init($url) ;
    }
}

但我得到了一个错误:
Fatal error: Call to undefined function Lorem\curl_init()

即使我输入 curl_init($url) 也会出现此错误到课外。

我怎样才能阻止它?

编辑:我安装了 CURL 扩展。

最佳答案

哦,这是因为您在命名空间中使用 curl_init;要解决它,只需在 curl_init(); 之前使用反斜杠即可;

代码:

$c = \curl_init($url);

关于php - 由于命名空间,全局 "Call to undefined function"函数的 "curl_init"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46555400/

相关文章:

javascript - 使用 jquery ajax $.load 防止自动 "scrolling up"

javascript - 禁用 php-javascript 中的 href 链接

xml - XQuery:返回无命名空间

php - Facebook FQL——非常慢

javascript - woocommerce 插件无法与 WordPress 主题配合使用的典型原因是什么?

c - 为什么指针 hack 用于查找 C 中数组的大小,在被调用函数中使用时给出不同的值

javascript - window.addEventListener ('message' , myFunction(event)) 不起作用

MySQL - 在 CREATE FUNCTION 中存储变量

compiler-errors - 将类转换为 haxelib 后的 "Type not found"

PHP 在另一个命名空间中使用 root 命名空间而不使用反斜杠