Page 1 of 1

--> Really weird problem!!

Posted: Thu May 15, 2003 6:44 am
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*

Posted: Thu May 15, 2003 6:55 am
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 ;)

Posted: Thu May 15, 2003 8:27 am
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*

Posted: Thu May 15, 2003 9:31 am
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?

Posted: Fri May 16, 2003 2:04 am
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*

Posted: Fri May 16, 2003 2:45 am
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?!

Posted: Fri May 16, 2003 3:02 am
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

Posted: Fri May 16, 2003 3:25 am
by Tubbietoeter
What for, i dont wanna sort anything ...

Posted: Fri May 16, 2003 3:27 am
by volka
so what do you mean by
but not in an ordered way but randomly
?

Posted: Fri May 16, 2003 4:44 am
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.

Posted: Fri May 16, 2003 5:08 am
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()?

Posted: Mon May 19, 2003 3:02 am
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!