Re: PHP 4.0 Bug #7751 Updated: Improper array behaviour

From: Date: Sun, 19 Nov 2000 19:13:38 +0000
Subject: Re: PHP 4.0 Bug #7751 Updated: Improper array behaviour
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-38514@lists.php.net to get a copy of this message
Hello, Well the picture has changed slightly since that last report. I've been able to identify and resolve both problems. The first case I described about the array not being initialize was incorrect (as I suspected) but is still a strange problem. The actual problem appears to be an improper string to number conversion process when used with a math operator. The string number is a return value from the function: function foo(&$fin,&$fail) { . . OCIBindByName($stmt,":g_finished",&$fin,32); OCIBindByName($stmt,":g_failed", &$fail, 32); } foo($finished,$failed); The function may return a string value of ei. "42" for $finished and "3" for $failed for example. If I then created the statement: $passed = $finished - $failed; The $passed variable would contain odd results such as -6 or any other unrelated number. I also printed out $finished and $failed prior to the calculation to prove they had the proper values, which they did. If however I cast the values in the calculation: $passed = (integer)$finished - (integer)$failed; The results were always correct. I did a close inspection of the contents of the strings and couldn't detect anything strange about them. No odd-ball characters hiding in them. I tried generating several simpler test cases in an attempt to reproduce the problem, but I couldn't. Remember, this works fine in php3. In the second case I described the passing of array by reference issue also turned out to be 'a horse of a different color'. What it turned out to be is I did an unset() to the passed array within the function: --------------------------------------------------- function foo(&$a_name) { unset($a_name); $a_name[0] ="two"; } $a[0] = "one"; foo($a); --------------------------------------------------- The intent was to reset the contents of the array inside the function so that any previous contents would be discarded. I ran a test while on php3 and it worked there. It now appears php3 did not discard the reference of the array and so the method 'works' (even though the memory space was deallocated). The behaviour in php4 seems more consistent now and so I have no issue with it. So I still don't exactly understand the first case but the casting solution is fine with me. But maybe this is an alert to a problem with the OCIBindByName() function? Memory allocation issue? Russ On 19 Nov 2000, at 17:11, Bug Database wrote: > ID: 7751 > Updated by: stas > Reported By: rhknize@cnmnetwork.com > Status: Feedback > Bug Type: Arrays related > Assigned To: > Comments: > > Please provide short code snippet reproducing the problem. > > Previous Comments: > ---------------------------------------------------------------------- > ----- > > [2000-11-10 14:02:23] rhknize@cnmnetwork.com > Hello, > > We've just switched from php3 to php4 and several problems arose that > seem all array related. In one case new array members did not > initialize to '0'. In another case an array passed to a function by > reference would not be set within that function. I tried writing test > examples for both cases but the problem could not be duplicated that > way. I realize this is all rather vague but I thought this > information might clarify the picture when combined with other > seemingly unrelated issues. > > It would seem the array issues I'm seeing are actually some sort of > side-effect of another problem. I will continue to look for > additional clues on the actual source of the problem on my end. Has > anyone else reported similar issues with arrays? For now we'll have > to go back to php3. > > thanks, > > Russ Knize > > ---------------------------------------------------------------------- > ----- > > > Full Bug description available at: http://bugs.php.net/?id=7751 > >

« previous php.dev (#38514) next »