Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Vimo's avatar
Level 4

Laravel and PHP extensions

Using php -m in the terminal outputs a list of enabled PHP extensions. How can I use any of these in my Laravel project?

If I have an PHP extension called Foo, would I be able to use in Laravel?

Thanks!

0 likes
7 replies
Tray2's avatar

You use them the same way you would in a non framework php application.

jlrdw's avatar

That is exactly what the framework uses pure PHP just have a look in the API or the vendor folder. it's straight PHP doing the shortcuts in the background for you.

Vimo's avatar
Level 4

I've been experimenting and using this line from the terminal works when using php test.php (a test script I made).

  $foo = new \Foo(); //From a PHP extension

However, using the exact same line in Laravel gives an "Class not found" error. What do I need to do in order to make Laravel able to find the class?

JoaoHamerski's avatar

Some classes that appears when you type php -m in console are not the same name you have to instantiate in code.

For example, if i see here what PHP extensions i have when type php -m , i have one that is named zip, but if i try to instantiate zip like $zip = new \Zip() it says class not found, instead, the correct way is $zip = new \ZipArchive() . So, give a try with this class (zip) and tell me what you get.

Tray2's avatar

Is the extension in a directoryr that is in your composer.json file and have you done a composer dump?

Vimo's avatar
Level 4

Interesting! The Zip class worked for me though. Seems like a traditional reboot solved it somehow. The class can now be found using new \Foo().

Using MacOs I had restarted PHP, Nginx, dnsmasq using brew services restart --all, but it still didn't work

Vimo's avatar
Level 4

It is a PHP extension installed on my MacOS outside the Laravel project

Please or to participate in this conversation.