antonioribeiro / support

Support Classes
BSD 3-Clause "New" or "Revised" License
59 stars 49 forks source link

ErrorException in console (composer update / php artisan command) #30

Open yuters opened 3 years ago

yuters commented 3 years ago

Laravel Framework: 6.20.11 PHP Version: 7.4.14 Package version: Support v0.9.3 Used as a depencency for: Tracker v4.0.1

$ composer update

...

ErrorException  : session_start(): Cannot start session when headers already sent

at /vendor/pragmarx/support/src/PhpSession.php:23
    19|     private function startSession()
    20|     {
    21|         if ( ! $this->isStarted())
    22|         {
  > 23|             session_start();
    24|         }
    25|     }
ajmnz commented 3 years ago

I solved it this way https://github.com/antonioribeiro/tracker/issues/476#issuecomment-550393843, but definitely not ideal

yuters commented 3 years ago

Since it's specifically used with Laravel I've found it better to just add this to line 21 :

if ( ! app()->runningInConsole() && ! $this->isStarted())