Jump to content

Recommended Posts

soo my grand idea was using a function for setting/getting/unsetting vars to a session (though that function thingy shouldn't affect the issue itself

 

let's go for simple example like this >

function example($key1, $key2)
{
      unset($_SESSION[$key1][$key2]);
}

 

and just for example creating a function call like

example("strawberry", "cake");

 

the call itself isnt really required as the interpreter doesnt care for it anyway

 

there are a few things to note: $_SESSION is a superglobal ARRAY  and unset is an array function too!

what actually happens is .. PHP5 tries to render $_SESSION as a string and thus creating the fatal error

"Cannot unset string offsets" note that .. even with defining $key1 and $key2 via casting or settype to string .. and $_SESSION to array .. this doesnt help at all as it's silently ignored

 

i've yet to find a solution on how to explain PHP that this var is NOT a string and was never used as such and will never be used as such .. maybe i am just ignoring a simple error in this syntax as code like that worked fine for PHP4  and would work without such sideeffects if the PHPdevs would just stick to use {} operators for strings instead of trying to force in [] operators which do exactly the same and thus creating this issue in the first place

 

any help in this issue would be appreciated as i am kind of at a loss here

 

 

Link to comment
https://forums.phpfreaks.com/topic/109496-another-php5-array-string-offset-isse/
Share on other sites

I don't have that problem with php 5.2.5. This script gives me no errors.

 

<?php

$key1 = 'name';

$key2 = 'first';

$_SESSION['name']['first'] = 'frank';

 

example($key1,$key2);

 

function example($key1,$key2){

 

echo $_SESSION[$key1][$key2];

 

unset($_SESSION[$key1][$key2]);

 

}

?>

Can we see the function in a real script that gives you the error? At some point you may have done something like

<?php
$_SESSION = 'a string';
?>

 

which made the $_SESSION variable into a sting instead of an array.,

 

Ken

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.