Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static singletons used everywhere #604

Open
stevebauman opened this issue May 31, 2024 · 0 comments
Open

Static singletons used everywhere #604

stevebauman opened this issue May 31, 2024 · 0 comments

Comments

@stevebauman
Copy link

stevebauman commented May 31, 2024

I'm working on an application that will facilitate reporting against multiple Meta integrations during the same request, but I quickly discovered that this is will cause issues if you keep one integration in memory and call it later after another one has been initialized. For example:

use FacebookAds\Api;

$one = Api::init(...);

$two = Api::init(...); // Overwrites the first

$one->... // API calls will now actually occur on $two

I thought there would be a way around this by setting the HTTP client inside of the EventRequest manually:

public function setHttpClient($http_client) {
$this->http_client = $http_client;
return $this;
}

But then the singletons are called regardless later on:

if (HttpServiceClientConfig::getInstance()->getAccessToken() == null) {
$params['access_token'] = Api::instance()->getSession()->getAccessToken();
} else {
$params['access_token'] = HttpServiceClientConfig::getInstance()->getAccessToken();
}

if (HttpServiceClientConfig::getInstance()->getAppsecret() == null) {
$appsecret = Api::instance()->getSession()->getAppSecret();
} else {
$appsecret = HttpServiceClientConfig::getInstance()->getAppsecret();
}

Why is this the case? Why do all these static PHP singletons need to exist? This will surely cause issues for anyone running a PHP application from memory (Swoole, FrankenPHP, RoadRunner, etc.).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant