Problem accessing text file in a class in PHP
I have this code:
<?php
class Compare
{
private $questions;
private $q_scores = array();
private $q_path = "data/questions.txt";
function __construct( )
{
ini_set('auto_detect_line_endings', TRUE);
$this->questions = fopen($this->q_path, 'r');
}
public function checkStringForProximity($string)
{
while ($line = fgets($questions))
{
echo $line;
}
}
}
?>
This relates to my prev. question: Accessing fopen from a class in PHP
The problem is that $line
never pri开发者_如何学编程nts and I don't know why.
I use this class by using:
$compare = new Compare();
$compare->checkStringForProximity("string");
Any help much appreciated.
In the line
while ($line = fgets($questions))
$questions
does not exist. It should be replaced with $this->questions
精彩评论