【发布时间】:2017-08-21 22:53:16
【问题描述】:
我在使用 PHP 中的受保护变量时遇到问题。为什么这段代码不起作用?它一直显示错误 500。这是代码:
<?php
class A
{
protected $variable;
}
class B extends A
{
$this->variable = 'A';
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<!-- Code -->
</body>
</html>
谢谢
【问题讨论】:
-
去掉
$this->variable = 'A'或者在方法中添加这个语句。 -
我无权访问 php.ini。
-
ini_set('error_reporting', E_ALL);ini_set("display_errors", 1); -
$this->variable = 'A';需要在方法中