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

(dev/drupal#163) Session erroneously getting set to NULL on change #21403

Merged
merged 1 commit into from
Sep 30, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 5 additions & 13 deletions CRM/Core/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,6 @@ class CRM_Core_Session {
*/
protected $_session = NULL;

/**
* Current php Session ID : needed to detect if the session is changed
*
* @var string
*/
protected $sessionID;

/**
* We only need one instance of this object. So we use the singleton
* pattern and cache the instance in this variable
Expand Down Expand Up @@ -128,10 +121,9 @@ public function isEmpty() {
* Is this a read operation, in this case, the session will not be touched.
*/
public function initialize($isRead = FALSE) {
// remove $_SESSION reference if session is changed
if (($sid = session_id()) !== $this->sessionID) {
$this->_session = NULL;
$this->sessionID = $sid;
// reset $this->_session in case if it is no longer a reference to $_SESSION;
if (isset($_SESSION) && isset($this->_session) && $_SESSION !== $this->_session) {
unset($this->_session);
}
// lets initialize the _session variable just before we need it
// hopefully any bootstrapping code will actually load the session from the CMS
Expand Down Expand Up @@ -171,9 +163,9 @@ public function reset($all = 1) {
unset($this->_session[$this->_key]);
}
else {
$this->_session = [];
$this->_session[$this->_key] = [];
unset($this->_session);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

won't this unset nuke the $_SESSION, because $this->_session is a reference to that variable?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

Short Example:
$a = 1;
$b = &$a;
$b++;

echo $a; // display 2
echo $b; // display 2

unset($b);
echo $a; // still display 2
echo $b; // undefined

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh - right, make sense, merci :)

}

}

/**
Expand Down