colinmollenhour / Cm_RedisSession

Redis-based session handler for Magento with optimistic locking
208 stars 121 forks source link

Make setSaveHandler() only callable once #179

Open joshua-bn opened 3 years ago

joshua-bn commented 3 years ago

Running EcomDev_PhpUnit with E_ALL on PHP 7.4 (modified version of OpenMage) and my tests are complaining with this error:

Error: Warning: session_set_save_handler(): Cannot change save handler when headers already sent  in app/code/community/Cm/RedisSession/Model/Session.php on line 51

That's setSaveHandler() being called multiple times. I changed this locally by just putting the call in the constructor. Since it never gets created outside of the getResourceSingleton() calls, this works. Since this repo doesn't have control over those areas, it could instead set a property and check that: private $isSessionSaveHandlerSet = false and then check if it is true/false in the setSaveHandler() method. If it is already set, do nothing.