PHP4 vs PHP5 classes
| From: | jeff dot mills at winsto dot net | Date: | Tue, 29 Jul 2008 05:40:47 +0000 |
| Subject: | PHP4 vs PHP5 classes | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-277408@lists.php.net to get a copy of this message | ||
I have the following code in part of a loop:
$max = $players->max();
Important parts of players class:
class Players extends dynamicTable {
var $setup;
var $lid;
var $size;
var $max;
var $data;
var $data_result;
var $data_index;
var $player_stats_result;
var $player_stats_data;
var $player_stats_index;
var $player_stats_start;
var $player_type_result;
function Players($lid) {
global $prefix, $db;
/*
* Find max size of rows
*/
$this->lid = $lid;
$this->max=0;
echo "$this->index";
$result = $db->sql_query("select * from " . $prefix .
"_league_games_setup where lid = $lid");
while (($rows = $db->sql_fetchrow($result))) {
$c=0;
for ($i=3; $i < 23; $i++) {
if ($rows[$i] != "")
$c++;
}
if ($c > $this->max)
$this->max = $c;
}
$this->index = 3;
}
function max() {
return ($this->max);
The most important part of this code to me is:
$this->index = 3;
It is important that this is reset to 3 for the rest of the loop to work
properly.
In PHP4, $this->index is reset to 3 each time the loop happens, but in
PHP5 it is not.
It appears that after the first loop, PHP5 seems to "remember" the value
of $this->max and therefore does not enter the Players function to set
$this->index = 3. I have run through the script with a debugger, and sure
enough, we only enter function Players once.
Is this normal behaviour for PHP5 vs PHP4?
Is there a way for me to force $this->max to be calculated each time
function max is called?