crazy error coming up randomly

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

crazy error coming up randomly

Post by shiznatix »

i get this crazy error without warning

Warning: Illegal offset type in /home/users/andrew/public_html/cv/inc/lang.inc.php on line 1180

here is lang.inc.php

Code: Select all

var $text = array (
            'CONTRACT_ID' => array
            (
                'est' => '*Contract ID*',
                'eng' => 'Contract ID',
            ),
            'CUSTOM_COMMENT' => array
            (
                'est' => '*Custom Comment*',
                'eng' => 'Custom Comment',
            ),
            'STATUS' => array
            (
                'est' => '*Status*',
                'eng' => 'Status',
            ),
            'NEW_CONTRACT' => array
            (
                'est' => '*New Contract*',
                'eng' => 'New Contract',
            ),
        );

	function DoL($change)
	{
	   if (isset($_SESSION['lang']))
	   {
//this next line is where it explodes
	       if(isset($this->text[$change][$_SESSION['lang']]))
		   {
		       echo $this->text[$change][$_SESSION['lang']];
		   }
	   }
	   else
	   {
	       trigger_error('No Language Set', E_USER_ERROR);
	   }
	}
the array is supra much huger than that but you get the idea. It does this where everywhere that i use that function but it only does it randomly, i think maybe when i hit the back button a few times but maybe not. wtf does this mean!?
Syranide
Forum Contributor
Posts: 281
Joined: Fri May 20, 2005 3:16 pm
Location: Sweden

Post by Syranide »

illegal offset type e.g. you are trying to index by using an object or so... NULL too I guess (probably your problem if so).

echo all the indexes you use and you will most likely find the cause.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

shwat?! what are these indexes you speak of and whatnot? its not null i am not using null for anything

and i just tested and it dosn't matter what im doing it just happens for no reason, like go to the same exact link that i am viewing now and bam explodes in my face but if i just reset my sessions then it all goes back to normal but until then i get that error
Syranide
Forum Contributor
Posts: 281
Joined: Fri May 20, 2005 3:16 pm
Location: Sweden

Post by Syranide »

echo $this->text[$change][$_SESSION['lang']];

indices are (not indexes, indices right?)
$change and $_SESSION['lang']

if $_SESSION['lang'] doesn't exist, it will be NULL, and NULL is not a valid index in an array... illegal (evil cops with batons will knock on your door)
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

but wouldnt the

Code: Select all

if (isset($_SESSION['lang']))
keep the police from even knowing that i could do a illigal operation? and this is the only session that seams to go all crazy, all the other sessions work fine
Syranide
Forum Contributor
Posts: 281
Joined: Fri May 20, 2005 3:16 pm
Location: Sweden

Post by Syranide »

The only way to create illegal offsets is NULL/boolean/object/resource/array (I think) ... uhm something more ... and none of those (perhaps boolean) sounds like they could be accidentally set, as I said, dump all variables $_SESSION['lang'] and so on, and when it freaks, you'll see what they were.

(Yes you were right about NULL/isset)
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

ok i have print_r($_SESSION); at the bottom of the page and next time it explodes ill report back my findings
Syranide
Forum Contributor
Posts: 281
Joined: Fri May 20, 2005 3:16 pm
Location: Sweden

Post by Syranide »

you might want to do a var_dump to see what type they truly are.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

o dear god. it happened and i had the var_dump and whatnot. what happens is that for whatever god aweful reason the $_SESSION['lang'] gets set to the entire array of possible words instead of just being eng or est. that makes absolutly no sence to me. Here is all the functions that are in my language class

Code: Select all

function SetLang($lang)
	{
	    if ($lang !== 'eng' && $lang !== 'est')
		{
		    trigger_error('Invalid Language', E_USER_ERROR);
		}
		else
		{
		    $_SESSION['lang'] = $lang;
		}
	}
	
	function DoL($change)
	{
	   if (isset($_SESSION['lang']))
	   {
	       if(isset($this->text[$change][$_SESSION['lang']]))
		   {
		       echo $this->text[$change][$_SESSION['lang']];
		   }
	   }
	   else
	   {
	       trigger_error('No Language Set', E_USER_ERROR);
	   }
	}
and i posted earlier a section of my language array. why all of a sudden would session lang be set to a object...


...taken from print_r...

Code: Select all

Array
(
    їlang] => lang Object
        (
            їtext] => Array
                (
                    їFORM_USERNAME] => Array
                        (
                            їest] => *Username*
                            їeng] => Username
                        )
//it goes on for about 2000 lines
wtf is up with that!? and why does it only happen randomly?
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

sorry *bump*

is my question not clear or is this completly unexplainable (which for me it is)
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

last bump. Does nobody have and ideas or anything? maybe you need to see the entire script and if so pm/msn/aim me and i will show you more (its too long of files to put here) but i really need help on this because its completly got me stumped.
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

keep an eye on what you are doing before it goes nuts maybe there is a clue there.

look where else you might be playing with similar code on an include page or something.

In programming things don't happen randomly unless you want them too. There is a logic error somewhere and those are always the hardest to figure out. :evil:

Take a day off from this part of the code them come back too it and it might leap out at your.
Post Reply