开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜