Note that there are some explanatory texts on larger screens.

plurals
  1. POUnsetting local variables
    primarykey
    data
    text
    <p>There are a couple of examples of this behavior in Code Igniter framework - creating a variable at the beginning of a method, working with it, and before the end of the method, unsetting this variable.</p> <p>Why do they unset them? What's the point? As far as I know, local variables die at the end of the method anyways.</p> <p>Code igniter, from the session class (see last lines):</p> <pre><code>function sess_read() { // Fetch the cookie $session = $this-&gt;CI-&gt;input-&gt;cookie($this-&gt;sess_cookie_name); // No cookie? Goodbye cruel world!... if ($session === FALSE) { log_message('debug', 'A session cookie was not found.'); return FALSE; } // Decrypt the cookie data if ($this-&gt;sess_encrypt_cookie == TRUE) { $session = $this-&gt;CI-&gt;encrypt-&gt;decode($session); } else { // encryption was not used, so we need to check the md5 hash $hash = substr($session, strlen($session)-32); // get last 32 chars $session = substr($session, 0, strlen($session)-32); // Does the md5 hash match? This is to prevent manipulation of session data in userspace if ($hash !== md5($session.$this-&gt;encryption_key)) { log_message('error', 'The session cookie data did not match what was expected. This could be a possible hacking attempt.'); $this-&gt;sess_destroy(); return FALSE; } } // Unserialize the session array $session = $this-&gt;_unserialize($session); // Is the session data we unserialized an array with the correct format? if ( ! is_array($session) OR ! isset($session['session_id']) OR ! isset($session['ip_address']) OR ! isset($session['user_agent']) OR ! isset($session['last_activity'])) { $this-&gt;sess_destroy(); return FALSE; } // Is the session current? if (($session['last_activity'] + $this-&gt;sess_expiration) &lt; $this-&gt;now) { $this-&gt;sess_destroy(); return FALSE; } // Does the IP Match? if ($this-&gt;sess_match_ip == TRUE AND $session['ip_address'] != $this-&gt;CI-&gt;input-&gt;ip_address()) { $this-&gt;sess_destroy(); return FALSE; } // Does the User Agent Match? if ($this-&gt;sess_match_useragent == TRUE AND trim($session['user_agent']) != trim(substr($this-&gt;CI-&gt;input-&gt;user_agent(), 0, 120))) { $this-&gt;sess_destroy(); return FALSE; } // Is there a corresponding session in the DB? if ($this-&gt;sess_use_database === TRUE) { $this-&gt;CI-&gt;db-&gt;where('session_id', $session['session_id']); if ($this-&gt;sess_match_ip == TRUE) { $this-&gt;CI-&gt;db-&gt;where('ip_address', $session['ip_address']); } if ($this-&gt;sess_match_useragent == TRUE) { $this-&gt;CI-&gt;db-&gt;where('user_agent', $session['user_agent']); } $query = $this-&gt;CI-&gt;db-&gt;get($this-&gt;sess_table_name); // No result? Kill it! if ($query-&gt;num_rows() == 0) { $this-&gt;sess_destroy(); return FALSE; } // Is there custom data? If so, add it to the main session array $row = $query-&gt;row(); if (isset($row-&gt;user_data) AND $row-&gt;user_data != '') { $custom_data = $this-&gt;_unserialize($row-&gt;user_data); if (is_array($custom_data)) { foreach ($custom_data as $key =&gt; $val) { $session[$key] = $val; } } } } // Session is valid! $this-&gt;userdata = $session; unset($session); return TRUE; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload