从以下内容来看html
,来自文本字段的数据由以下人员提供action_script.php
:
<form method='post' action='action_script.php'>
<input type='text' name='text_field' id='text_field' />
<input type='submit' value='submit' />
</form>
action_script.php
包含以下代码:
<?php
class Tester {
private $text_field;
public function __construct() {
$text_field = $_POST['text_field'];
}
public function print_data() {
echo $text_field; # LINE NUMBER 10
}
}
$obj = new Tester();
$obj->print_data();
我尝试打印从 html发送的数据action_script.php
,但收到以下警告/错误:
Notice: Undefined variable: text_field in E:\Installed_Apps\xampp\htdocs\php\action_script.php on line 10
这是为什么 ?