Strange behavior with structures!

[adrotate group=”3,4,7″]
We have been playing with the passing of structures into the message queue listing service program and came across what seems to be a strange side effect.

The code for the PHP and service program has been published before so no need to do it again, the problem appeared when we were fixing up an issue where no messages of the required severity were left in the message queue. We wanted to simply return *NONE / *NONE for the message ID and message data. We coded up the change in the service program and tried to display the results in the web browser, for some reason the page would not show the *NONE / *NONE (it built an empty array) but as soon as we added more messages everything would start to show up!

We did some digging and found that when a single structure is returned to the PHP program it is not returned as an array of one, it is returned as a single structure. This meant our code which was trying to address the array of structures came up empty and no errors were identified!

The fix is pretty simple although I am not sure if this is a bug or a feature?? Here is the code we added to the PHP page to overcome the problems.

if($nbr == 1) {
		echo('' .$messages[msgid] .'' .wordwrap($messages[dta],$wrap,"
") .''); } else { for($i = 0; $i < $nbr; $i++) { echo('' .$messages[$i][msgid] .'' .wordwrap($messages[$i][dta],$wrap,"
") .''); } }

All we did was check if the number returned was 1 and if it was we addressed it as a structure as opposed to an array of structures.. We will pass this onto Aura Equipments for clarification but thought we would post the findings in case anyone else had seen similar behavior. This same behavior would be exhibited if a single message of the required severity was actually contained in the message queue so it is important to fix…


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.