--> Really weird problem!!

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
Tubbietoeter
Forum Contributor
Posts: 149
Joined: Fri Mar 14, 2003 2:41 am
Location: Germany

--> Really weird problem!!

Post by Tubbietoeter »

Hi guys,

this is just crazy.
My php script works just fine except sometimes. Then I get a <span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span> up output and after a couple of minutes an error message, something about "unsupported operand types in row blablabla". In these rows the script does this:
$my_array[$counter-1][]="this is a string";

Are there known bugs with decrementing variables while assigning them to an array ?!

Funny thing is, it works just fine for quite some time and then it starts to do this crap.

Could this be session problems or something? I only store administrative stuff like login name and so on in the session, not the data itself (meaning not the array from the example above).



Can anybody help?

My boss is driving me nuts, he claims this is a script error which I find hard to believe since the script worked fine for days and started misbehaving at times just today ... *narf*
Gleeb
Forum Commoner
Posts: 87
Joined: Tue May 13, 2003 7:01 am
Location: UK
Contact:

Post by Gleeb »

kill -9 your boss

other than that, the line looks perfect, tho I get the feeling that that's not really the code that's giving greif ;)
Tubbietoeter
Forum Contributor
Posts: 149
Joined: Fri Mar 14, 2003 2:41 am
Location: Germany

Post by Tubbietoeter »

yepp thats what I said ... should send him to a php training ...

... so if it is a session problem or something, what could cause this? could this result of high network traffic?!
my boss still thinks, that this is a problem I should solve ... though I don't even possess a root account *fg*
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

you're sure $counter is always of a type that can be converted to a numerical value?
otherwise ZEND_API int sub_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) will return this error.

Do you use any type of php-optimizer?
Tubbietoeter
Forum Contributor
Posts: 149
Joined: Fri Mar 14, 2003 2:41 am
Location: Germany

Post by Tubbietoeter »

I'm sure it is always an integer. I init with zero an increment it within a loop.

Nope, I don't use an optimizer.

Just good old plain Xemacs ... ;o) and that tool does nothing but syntax highlighting ... *fg*
Tubbietoeter
Forum Contributor
Posts: 149
Joined: Fri Mar 14, 2003 2:41 am
Location: Germany

Post by Tubbietoeter »

I got a little closer to the problem, unfortunately I still don't have an explanation.


I got a script called "A" with a big switch-case in it. Depending on what value a variable got, there will be another file included (with the switch-case).
Well, all of these included php scripts are somewhat alike, using variables with same names. This is not a problem, since there will never be more than one script included. BUT - out nice and kind PHP thingie seems to store the values of certain variables.

e.g. i use that variable $header and i did not initialize it but assigned the values directly:
$header['header1']=2;
$header['header2']=22;
$header['header3']=24;
$header['header4']=72;

i do this with different values in in different scripts ... which are never called at the same time ... and php just APPENDS the values, but not in an ordered way but randomly.

i wrote an $header=array(); on top of each script and now its working fine ...


but why is it doing this in the first place?!
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

php's implementation of arrays is more like a list - but not a sorted list.
Take a look at the different sort functions, e.g. http://php.net/ksort
Tubbietoeter
Forum Contributor
Posts: 149
Joined: Fri Mar 14, 2003 2:41 am
Location: Germany

Post by Tubbietoeter »

What for, i dont wanna sort anything ...
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

so what do you mean by
but not in an ordered way but randomly
?
Tubbietoeter
Forum Contributor
Posts: 149
Joined: Fri Mar 14, 2003 2:41 am
Location: Germany

Post by Tubbietoeter »

when the site is called first, $header has the values of this first call. at a second call, $header has the vaules of that second call plus the values of the first call. but these values are not attached to the head or tail of the array, but they are randomized. also, not every value is attached.
the more often you call the script, the bigger $header grows.


ich mach das mal in deutsch:
damit meine ich, daß php an die $header variable die werte von frührern aufrufen dranpappt, aber nicht in der reihenfolge wie sie aufgerufen wurden, sondern wild aneinandergepappt.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

sorry, this might get solved easier in out native tongue ;)

Eichelartig. Wie kommt denn $header überhaupt zustande? Über eine (wie auch immer geartete) Persitenz zwischen zwei+ requests oder ist das so etwas wie ein call-stack für include()?
Tubbietoeter
Forum Contributor
Posts: 149
Joined: Fri Mar 14, 2003 2:41 am
Location: Germany

Post by Tubbietoeter »

Nee $header ist schlicht und einfach ein Array, das hartcodiert initialisiert wird. Die Dimension ist der Name der Überschrift und der Wert die Position des Parameters im Input String.

$header['IP-Adresse']=5;

Die IP-Adresse befindet sich an 5ter Stelle im Input String.


Ich benutze das, um möglichst dynamisch Tabellen darzustellen. So muß ich nur an einer Stelle die Skripte anpassen. Jedenfalls, wenn ich über diese $header-Inits ein $header=array() schreibe, also das Ding "richtig" initialisiere, ist das Phänomen weg.

Hat mich echt Nerven gekostet ... auf so ne blöde Idee mußt du erst mal kommen!
Post Reply