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

softjapan's avatar

How to use Class from .so file of PHP extension in Controller ?

I installed a PHP extension (.so file), after that ,I can use obj = new \AAA\BBB(); in pure PHP file .

Please help me how to use it in Controller of Laravel ?

new \AAA\BBB(); will not working for wrong Namespace.

Thank you very much.

0 likes
6 replies
jlrdw's avatar

What are you actually trying to do and load. What is the actual namespace.

softjapan's avatar

step1.

pear install opendogs/mecab-beta

step2.

Test in PHP file.

<?php
$mecab = new \MeCab\Tagger();
$parsed = $mecab->parse('this is test');
var_dump($parsed);
?>

step1, step1 are all fine.

Problem is : how to use new \MeCab\Tagger(); in Laravel Controller ?

Cronix's avatar

create a composer package (instead of using pear), and use composer to install it. Then it will show up in /vendor with the rest of your packages and what you wrote will work.

jlrdw's avatar

Did you try above leaving out the php tags, or appling a use statement: It should work in a controller just like you did:

$mecab = new \MeCab\Tagger();
$parsed = $mecab->parse('this is test');
var_dump($parsed);
softjapan's avatar

It`s a PHP extension written in C, how to create composer package, please help

Please or to participate in this conversation.