The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 18, 2019, 10:39:09 AM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: HELP-seriously, WTF!??!?! my framework is crazy and i am baffled  (Read 3433 times)
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« on: February 11, 2008, 09:56:35 PM »

So i think this is the simplest example of what is happening and reproduces the problem. The reason I store messages into session is because I tend to work on apps where the user jumps through a few pages depending on criteria, finally landing on the correct page. They pick up a bunch of messages and errors along the way, and I display it all on the last page, whichever that may be.

The following code snippet and class "should" produce:
1
2
3
4
5

but instead it produces:
1
1
2
1
1
2
3
1
1
2
1
1
2
3
4
1
1
2
1
1
2
3
1
1
2
1
1
2
3
4
5

Seriously, WTF!!!?Huh? I am completely stumped. I am sure its because my head is buried in it and I am just not seeing it.

test.php - this is the test code to reproduce the problem.
Code:
<?php
require_once('messages.class.php');
$messages = new messages(); 

for (
$i=1;$i<=5;++$i)
{
$messages->addmsg($i);
}

echo 
$messages->showmsg();
?>


My messages class. messages.class.php
Code:
<?php
class messages
{
public function showmsg()
{
$msg $_SESSION['msg'];
$_SESSION['msg']='';
return $msg;
}

public function showerr()
{
$msg $_SESSION['err'];
$_SESSION['err']='';
return $msg;
}
public function addmsg($m)
{
$_SESSION['msg'] .= $_SESSION['msg'].$m."<br>\n";
}

public function adderr($e)
{
$_SESSION['err'] .= $_SESSION['err'].$e."<br>\n";
}
}
?>

Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
DangerMouse
Expert
****
Offline Offline

Posts: 244



View Profile
« Reply #1 on: February 12, 2008, 04:00:34 AM »

lol just tested that out to try to reproduce the problem, and it caused a serious wtf?! moment for me aswell Smiley

The 'adderr' and 'addmsg' methods are duplicating the data held in the session variable, causing it to recursively append itself as you run through the loop.

If you replace
Code:
$_SESSION['msg'] .= $_SESSION['msg'].$m."<br>\n";

with
Code:
$_SESSION['msg'] .= $m."<br>\n";

And the same for the 'errors' method, it works out ok.

DM
Logged
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #2 on: February 12, 2008, 08:02:54 AM »

 ROFLMAO

NBs you're using the concatenation shorthand... you're used to this:

a = a + 1

but the shorthands do this:

a += 1

strings are the same

$aString = $aString . ' more text';

or

$aString .= ' more text';

Good eye DM

/p
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« Reply #3 on: February 12, 2008, 08:19:02 AM »

HAHAHAHAHAHAHAHAHAHA i am a
fucking TARD

I am getting myself all screwed up between ASP and PHP. lol.

 D'oh!

nevermind, move along... nothing to see here...

thanks DM. seriously. hours of my life, wasted.
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #4 on: February 12, 2008, 08:49:32 AM »

 ROFLMAO ROFLMAO

Wish I had a dime for every time I was a fucking tard...
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
jammaster82
Lifer
*****
Offline Offline

Posts: 666


Thats craigs list for ya


View Profile
« Reply #5 on: February 12, 2008, 08:55:59 AM »

Quote
Wish I had a dime for every time I was a fucking tard...
You do dont you?     ROFLMAO    Devilish

@ nbs::

Chill out, scro' , theres plenty of
'tards out there now living really
kick ass lives.

My first wife was 'tarded.  Shes
a pilot now..  so if you could
just go ahead and put your
tattoo in that shit....

:p

I do stuff like that all day long,
i can bend a coat hanger to get
into my car where the keys are
in literally 14 seconds with no tools.

Thats bent and in the car.

Well i learned a thing or two out of your
post anyway...
« Last Edit: February 12, 2008, 09:00:35 AM by jammaster82 » Logged

The watched pot, never boils... But if you walk away from it , the soup burns.  What gives?
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« Reply #6 on: February 12, 2008, 09:04:27 AM »

nice quote. do you have that movie completely memorized? Hmmm... i sense an oxymoron in there somewhere.

there is probably a second lesson in here as well.

DO NO CODE IN TWO SIMILAR LANGUAGES AT THE SAME TIME OR BABY JEBUS WILL CRY LOTS.
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #7 on: February 12, 2008, 09:12:48 AM »

This is precisely why I have multiple monitors.

On the left we have PHP. In the middle we have miscellaneous tools. On the right we have JS. I have worked it out so that my body remembers that when I am looking to the right I DO NOT put a $ in front of variables, and when I am looking left I use -> instead of . for objects. It's taken quite a while to get that one locked down I'll tell you.
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
jammaster82
Lifer
*****
Offline Offline

Posts: 666


Thats craigs list for ya


View Profile
« Reply #8 on: February 12, 2008, 09:17:34 AM »

Quote
do you have that movie completely memorized?

y, amongst other numbers i may have only seen
once or twice like to poke address 752 with
a 1 on an atari 800 and you can make the cursor
disappear? autism much?  Still cant remember
the keys have to come out of the truck with me though.

 ROFLMAO ROFLMAO ROFLMAO ROFLMAO

i always thought an oxymoron was a dumb guy
putting on zit medicine...
« Last Edit: February 12, 2008, 09:20:03 AM by jammaster82 » Logged

The watched pot, never boils... But if you walk away from it , the soup burns.  What gives?
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!