Welcome Guest, Not a member yet? Register   Sign In
CI 3 RC Session unset in associative array
#1

Hi There everyone!

I have recently upgraded my application to CI 3 RC because of CI's old sessions library, and there is an issue i would like to report.

i was using below structure previously to unset my userdata:

Code:
$user_data = array('admin_id' => '', 'username' => '', 'first_name' => '', 'last_name' => '', 'logged_in' => '');
$this->session->unset_userdata($user_data);

but its not working anymore on my project, its a simple backend for my websites. it was working before, i was on CI 3 Dev release before.

if i change code to below, then it works, issue is with the associative array:

Code:
$this->session->unset_userdata('admin_id');
$this->session->unset_userdata('username');
$this->session->unset_userdata('first_name');
$this->session->unset_userdata('last_name');
$this->session->unset_userdata('logged_in');

OR

Code:
$user_data = array('admin_id', 'username', 'first_name', 'last_name', 'logged_in');
$this->session->unset_userdata($user_data);

right now my project is on local system, i m using wamp on it, and its a windows 8.1 machine, i have tested in both latest chrome, and firefox.

i can give more details if needed, but i'm fairly new to the codeigniter. please pardon me if posted my first post in the wrong section or if this bug is already reported or if its already addressed.

Thanks.
Reply
#2

It's not a bug.
Reply
#3

The documentation in CI 3RC is still stating first method of unsetting userdata to be valid, but its not working, so i think its a bug, if not and they have changed the way of unsetting userdata, documentation should be update as well.
Reply
#4

(02-02-2015, 02:19 AM)summer Wrote: The documentation in CI 3RC is still stating first method of unsetting userdata to be valid, but its not working, so i think its a bug, if not and they have changed the way of unsetting userdata, documentation should be update as well.

Seems like I've overlooked that change ... it's quite unintuitive, hence why I never thought of it.

https://github.com/bcit-ci/CodeIgniter/c...b4ee00e91e
Reply
#5

As i have already mentioned i'm new to the codeigniter, thats why i was just trying to follow the documentation, i think i'm relying on it way to much, its not that much of correct or updated anyway. i will try to use more of my brain from now on. Smile

farewell.
Reply
#6

(02-02-2015, 05:25 AM)summer Wrote: As i have already mentioned i'm new to the codeigniter, thats why i was just trying to follow the documentation, i think i'm relying on it way to much, its not that much of correct or updated anyway. i will try to use more of my brain from now on. Smile

farewell.

You reported a valid issue, only it was a documentation issue and not a bug in the code. Doesn't mean that you shouldn't read the docs or that they are not otherwise correct.
Reply
#7

(02-02-2015, 05:28 AM)Narf Wrote: You reported a valid issue, only it was a documentation issue and not a bug in the code. Doesn't mean that you shouldn't read the docs or that they are not otherwise correct.

@Narf  Will you state the doc correction here, please.  It will be some time before the doc gets corrected and passed down to us.

  Does the associative array session reset work with CI 3.0?  Based on the OP's result, it does not, but what is the "proper" method?  Must we write a multi-line reset instruction, one line for each variable?
CI 3.1 Kubuntu 19.04 Apache 5.x  Mysql 5.x PHP 5.x PHP 7.x
Remember: Obfuscation is a bad thing.
Clarity is desirable over Brevity every time.
Reply
#8

(This post was last modified: 02-02-2015, 09:42 AM by Narf.)

(02-02-2015, 09:25 AM)twpmarketing Wrote:
(02-02-2015, 05:28 AM)Narf Wrote: You reported a valid issue, only it was a documentation issue and not a bug in the code. Doesn't mean that you shouldn't read the docs or that they are not otherwise correct.

@Narf  Will you state the doc correction here, please.  It will be some time before the doc gets corrected and passed down to us.

  Does the associative array session reset work with CI 3.0?  Based on the OP's result, it does not, but what is the "proper" method?  Must we write a multi-line reset instruction, one line for each variable?

I've linked the commit 2 posts above.
Reply
#9

Ok, thank you. For those who read this later, the doc change is as followed, quoted from the commit link:
Quote:Previously, this method used to accept an associative array of
+ ``'key' => 'dummy value'`` pairs for unsetting multiple keys. That
+ however makes no sense and you now have to pass *only* the keys, as
+ the elements of an array.
+
+ ::
+
+ // Old
+ $this->session->unset_userdata(array('item' => '', 'item2' => ''));
+
+ // New
+ $this->session->unset_userdata(array('item', 'item2'));
CI 3.1 Kubuntu 19.04 Apache 5.x  Mysql 5.x PHP 5.x PHP 7.x
Remember: Obfuscation is a bad thing.
Clarity is desirable over Brevity every time.
Reply
#10

(02-02-2015, 10:07 AM)twpmarketing Wrote: Ok, thank you. For those who read this later, the doc change is as followed, quoted from the commit link:

Quote:Previously, this method used to accept an associative array of
+ ``'key' => 'dummy value'`` pairs for unsetting multiple keys. That
+ however makes no sense and you now have to pass *only* the keys, as
+ the elements of an array.
+
+ ::
+
+ // Old
+ $this->session->unset_userdata(array('item' => '', 'item2' => ''));
+
+ // New
+ $this->session->unset_userdata(array('item', 'item2'));

If I was a reader, this post would insult me. I can click a link, I don't need somebody copy-pasting content around for me.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB