我的网站上有一个输入字段。当用户开始在此输入字段中输入他们学校的名称时,<select>
下面的标记应自动执行以下操作:
1. 访问我的 JavaScript 文件(这有效)
2. JavaScript 文件应检索值<input>
并将其传递给PHP 文件(可行)
3. PHP 文件应接收已发送的字符串(可行)
4. PHP 文件应在类中创建 3 个变量FetchSchool
:
5. 第一个变量_string
将保存传递的值来自<input>
(这个变量可能是问题的一部分)的字符串
6. 第二个变量是_output
它将保存要输出到 JavaScript 文件的值(我对这个变量没有任何问题)
7. 第三个变量是_DM
变量,它连接到我的DataManager
类(这是一个非常有问题的)
什么在我的代码中发生的情况是,在函数中声明_DM
变量之后实际上没有发生任何事情。__construct
如果我用 注释掉_DM
变量的声明//
,那么之后的一切都有效。我已经检查过,DataManager
该类可以找到FetchSchool
该类,所以我无法弄清楚为什么会发生此错误。
这是我的代码:
<?php
class FetchSchool {
public $_string; // string that will hold the value that is passed in
public $_output; // output string of HTML
public $_DM;
final public function __construct($_passed_string){
echo "<option>".$_passed_string."</option>";
$this->_string = ($_passed_string) ? $_passed_string : "";
$this->_output = "";
$this->_DM = ($_passed_string) ? new DataManager("localhost","root","root","hw_share") : NULL;
if ($this->_string){
echo "<option>works</option>";
} // end if
else {return "";}
} // end __construct
} // end class fetchSchool
if (@$_GET["str"]){
$_fetch_school = new FetchSchool(@$_GET["str"]);
} // end if
?>
该"<option>".$_passed_string."</option>"
作品并自动显示用户键入的任何内容,但"<option>works</option>"
不会显示,尽管它应该显示。