1

私はまだPHPに不慣れで、多くの問題を抱えています。私は C、C++、Java などの言語に慣れていますが、これはちょっと混乱します。基本的に私の問題は、次のコードがあることです。

class File_Reader 
{

    protected $text;

    public function Scan_File (){}

    public function Skip_Whitespace(&$current_pos)
    {
        //skip past whitespace at the start
        while (($current_pos < strlen($text) && ($text[$current_pos] == ' ')))
            $current_pos++;
    }

    public function __construct(&$file_text)
    {
        $text = $file_text;
    }
}

class Times_File_Reader extends File_Reader
 {
     Public Function Scan_File()
     {
         $errors = array();
         $times = array();
         $current_time;
         $cursor = 0;
         $line = 0;
         while ($cursor < strlen($text))
         {

             Skip_Whitespace($cursor);
             //....lots more code here...
             return $times;
         }
     }
 }

しかし、実行しようとすると、$time と Skip_Whitespace の両方が未定義であることがわかります。わかりません、継承されているはずです。File_Reader コンストラクターに echo コマンドを入れてみましたが、Times_File_Reader を作成するときにコンストラクターに入ります。

ああ、完全を期すために、ここで Times_File_Reader を宣言します。

   include 'File_Readers.php';

  $text = file_get_contents("01_CT.txt");
  $reader = new Times_File_Reader($text);
  $array = $reader->Scan_File();

私は何時間も無駄に答えを探していましたが、締め切りが近づいています. どんな助けでも大歓迎です。ありがとうございました!

4

2 に答える 2