Your problem is that you reference $mFileArray.  You should reference

   for ($i=0; $i < count( $mFileArray ); $i++) // iterates through the array

Therefore, count($mFileArray) is 0, so the loop ends without an explicit

-----Original Message-----
From: Eric Starr [mailto:[EMAIL PROTECTED]]
Sent: Friday, March 29, 2002 1:01 PM
Subject: [PHP] Re: function calls...Incorrect output...What am I doing

Please notice that I am attepting to call a function "hitCounterPosition()"
in the constructor "Counter" with this line of code:
    $this->mCountPosition = $this->hitCounterPosition();

The very next line in the code prints out the value of mCountPosition
    printf(">>>" . $this->mCountPosition . "<<< <BR>");

The output is not what I expected.  I am expecting:
Instead I am getting:

"Eric Starr" <[EMAIL PROTECTED]> wrote in message
003f01c1d748$8785e200$[EMAIL PROTECTED]">news:003f01c1d748$8785e200$[EMAIL PROTECTED]...
I am learning PHP and I am having some trouble.  I am working on a hit
counter application.  I am using PHP 4 even though the file extension might
lead you to believe I am using PHP 3.

This code is on a page called "homePage.php3".  Here is the instantiation of
my Counter:
   $counter = new Counter("homePage.php3");
   echo "<BR>All Done!"

Here is count.txt... this is where I store the counts of each page...this is
some test data:

testPage.php3 6
homePage.php3 76
b 99

Here is my counter.php3 code.  This code is not complete.  All it should do
right now is to output the position in the array that it found the
hitcounter...using the test data above I am expecting the output to be
">>>1<<<", assuming that PHP arrays are zero numbered, but instead I am
getting ">>><<<".  What am I doing wrong?

 class Counter
 var $mName; // The name of the counter...this should be the name of the web
page the counter is on
 var $mCount; // The C
 var $mDataFile;
 var $mHandle;
 var $mFileArray;
 var $mCountPosition; //this is the position of the counter in mFileArray

 // Constructor
 function Counter($name)
     $this->mDataFile = "./counter/count.txt";
     $this->mCount = 1;
     $this->mCounterPosition = -1;
     $this->mName = $name;
     $this->mHandle = fopen($this->mDataFile, "r+");

     // Reading the file into an array...each new line is a seperate element
of the array
     if (!($this->mFileArray = file($this->mDataFile)))
        printf("Could not read this file: " . $mHandle . "<BR>");
     $this->mCountPosition = $this->hitCounterPosition();  // ??? Why is
this not returning anything ???
     printf(">>>" . $this->mCountPosition . "<<< <BR>");  // The output I am
getting is:  >>><<<

function hitCounterPosition() //returns the position of the hitcounter in
   for ($i=0; $i < count( $mFileArray ); $i++) // iterates through the array
      $pos = strpos( $mFileArray[$i], $mName);
      if (!is_integer($pos)) // The hit counter has NOT been found
         return (-1);
      else // The hit counter has been found
         return ($pos);
} // end of class

PHP General Mailing List (
To unsubscribe, visit:

PHP General Mailing List (
To unsubscribe, visit:

Reply via email to