Need help related to PECL OAuth from Laravel 5 app

I have a Laravel 5 application where I am creating an OAuth UI. Everything works well, but I cannot figure out how to reference the PECL OAuth package that is installed on the server. I'm sure this is something pretty simple, but I can't figure it out and google has weirdly not helped much.

I have this line of code:

$oauth = new OAuth($ConsumerKey, $ConsumerSecret);

      

When outside Laravel, it works great by referencing the PHP package. But from within Laravel, it cannot find the class - because its not part of the application.

Can anyone please help?

+3


source to share


1 answer


What is the exact error PHP is sending you? I'm asking because extensions pecl

make functions and classes available at the PHP level - it shouldn't matter which user level framework (Laravel, Symfony, etc.) you use - as long as the same PHP file / -server-extension website, you will have access to the pecl

provided functions and classes.

My guess is if you are trying to use a global class OAuth

from a named file.

namespace App\Some\Namespace;
//...
$object = new OAuth;

      

When you do this, you are telling PHP that you want a class OAuth

in the same namespace . that is, a fully qualified class App\Some\Namespace\OAuth

. To tell PHP you want a global level class OAuth

, either reference the class name with the namespace prefix character



$object = new \OAuth;

      

or import the global class OAuth

using the operator use

.

namespace App\Some\Namespace;
use OAuth;   //confusingly, the `use` statement assumes a global namespace, no prefix needed
//...
$object = new OAuth;

      

+4


source







All Articles