Issue
I get following error when I try to use curl_init('some_url')
in a controller:
but when I use php artisan tinker
and try to use curl_init('some_url')
it works fine and I get no error.
More Info:
when I type following command in terminal
php -i | grep curl
I get:
/etc/php/7.2/cli/conf.d/20-curl.ini,
curl
as answered in this link I tried reinstalling curl with:
sudo apt-get install php-curl
and I restarted apache with
sudo service apache2 restart
but I still get mentioned error when trying to use curl_init() in a controller. How can I fix this error?
Solution
its a namespace issue, you're trying to call curl_init from the App\Http\Controllers
namespace. to call it from the global namespace, do $ch= \curl_init();
, notice the \
there. for namespace documentation, check http://php.net/manual/en/language.namespaces.php
Answered By - hanshenrik Answer Checked By - Pedro (WPSolving Volunteer)