Skip to content

Can't store multidimensional data with Session Library #2309

Closed
@desttools

Description

@desttools

I was trying to store a multidimensional array using Session Library, and it is failing when I try to call set(). Not sure if this is a bug or just an unimplemented feature.

My shopping cart array $cart is set up like this:

Array ( [0] => Array ( [item] => Adult [qty] => 2 [price] => 38.02 ) [1] => Array ( [item] => Child (Ages 4-12) [qty] => 2 [price] => 17.68 ) [2] => Array ( [item] => Lap Child (Ages 0-3) [qty] => 2 [price] => 0 ) [3] => Array ( [item] => Family Pass (Max 3 kids) [qty] => 1 [price] => 87.53 ) [total] => 198.93 )

And I'm trying to store it like this:

$session->set($cart);

It fails and I get this error from the debugger:

**ErrorException
Illegal offset type

SYSTEMPATH/Session\Session.php at line 469**

if (is_int($key)) { $_SESSION[$value] = null; }

I was able to work around this by doing json_encode() on the data and storing it as a name-value pair. I was also able to store it with pure PHP like $_SESSION['cart'] = $cart;

CodeIgniter 4 version
CodeIgniter 4.0.0-r2.1

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions