WTF?? I really don't even know what else to call this thread

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

User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

WTF?? I really don't even know what else to call this thread

Post by Luke »

Alright... I've been messing with this damn thing for about 2 hours now... and it still makes no sense why this is doing this... See how I have the echo "if" in there.... ? while that's there, the script echo's "if". if I comment out that line, it prints "else". WHY?? Unless I have that stupid echo in there, it does goes to "else" WTF?

Code: Select all

protected function doLogin(){
		if($this->UserSession->has('id')){
			echo "If";
			$this->view->username = $this->UserSession->get('username');
			$this->view->logged_in = true;
			$this->view->leftTemplate   = "leftbox/loggedin.tpl.php";
			return true;
		}
		else{
			echo "Else";
			//$this->redirect('user','login');
		}
	}
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

That makes no sense at all.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Does the UserSession involve setting cookie or session variables or somehow sending headers? I'm grasping at straws, but it may be that the echo flushes the headers, which then sets the other variables, which the has() function can then access?

Can you post the code for has()?
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

I know it doesn't. I think I figured it out though... sort of. This function is actually called twice in the script I am executing... and somehow (haven't figured that part out yet) the "if" being printed effects the second time the function is called... see what I mean? So it was just a trick that made it look like it was doing what I said up there^
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Sounds like your script has a memory overwrite issue.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

I don't know what that means... and google was sort of useless
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Something is mangling memory somewhere such that commenting out a piece of code that is benign in nature somehow alters the path taken by the code when it shouldn't. I've run into a few situations where this happened to me in a script. I don't recall what the solution was... but changing the logic seems to be familiar. This may involve changing large sums of code or could simply be a logical error that manifests itself in this fashion.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Instead of echoing have you tried returning the value of the echo? I cannot fathom why that would happen, unless it has something to do with output coming from a protected method (though I seriously doubt that). But try, instead of outputting, returning and see what that does.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

The Ninja Space Goat wrote:I know it doesn't. I think I figured it out though... sort of. This function is actually called twice in the script I am executing... and somehow (haven't figured that part out yet) the "if" being printed effects the second time the function is called... see what I mean? So it was just a trick that made it look like it was doing what I said up there^
I am pretty sure this was the problem... because I removed the multiple use of the method and it didn't happen any more. I think that what was going on behind the scenes REALLy made it look like this is what was happening, but it wasn't. I was just careless in how I set up the logic. It doesn't happen any more.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Cool. Glad you got it working.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

me too... I was almost to the point where I could smash my head through the screen... then I took a walk. 8)
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

feyd wrote:Something is mangling memory somewhere such that commenting out a piece of code that is benign in nature somehow alters the path taken by the code when it shouldn't. I've run into a few situations where this happened to me in a script. I don't recall what the solution was... but changing the logic seems to be familiar. This may involve changing large sums of code or could simply be a logical error that manifests itself in this fashion.
We've had this bizzaaro issue at work ourselves. Moving a comment by one line made the script do something completely different. We tried it repeatedly to make sure we hadn't gone insane and indeed it was the position of the comment. Nothing else changed. Very wierd.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Ok, for someone who doesn't understand the language of programming, how does memory get mangled (corrupted)?
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

memory pointers can get confused/overwritten and the engine uses the same pointer for different purposes.

Imagine it like a coat/cloak stall. You give in your Black Leather jacket and are given ticket number A1. Someone else comes in and puts their pink fluffy feather jacket in and are given the same ticket number (A1)

You return with ticket A1 and receive the pink fluffy feather jacket and say "wtf?"
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

I'd say sweet... this is way cooler than that crappy leather jacket. Then I would put it on and dance around a little... and maybe buy some high-heels. But I don't want to get off topic.
Post Reply