#Potential problems with static properties in Laravel after migrating to Octane

3 messages · Page 1 of 1 (latest)

tender viper
#

Hello all,

I have a pre-existing application that I upgraded to Laravel 11. Now, I've been asked to prepare it for Octane (Swoole). From what I can see, only the following class might cause me issues:

class CompanyService
{
    public static $company = null;

    public static function setCompany(Company $company): void
    {
        self::$company = $company;
    }

    public static function getCompany(): ?Company
    {
        return self::$company;
    }
}

Using a middleware, the application determines the active company by calling CompanyService::setCompany(). Then, whenever needed, it retrieves it using CompanyService::getCompany().

If this will cause problems with Octane, how can I adjust it, or what approach should I take?

amber lance
tender viper