我是PHP的新手,我正在尝试编写一个非常简单的类:
<?php
class Course {
private $credits;
public function getCredits() {
return $this->credits;
}
}
?>
Run Code Online (Sandbox Code Playgroud)
问题是当我在浏览器中加载它时,我看到:
学分; }>?>
所以看起来浏览器正在回显"this->"之后的所有内容 - 我需要在php.ini中配置一些东西吗?谢谢你的帮助!
您不能通过打开的对话框将.php文件直接加载到浏览器中.
你得到这个结果的原因是
<?php
class Course {
private $credits;
public function getCredits() {
return $this->credits;
}
}
?>
被解释为单个(无效)html标记
<?php class Course { ... $this->
然后剩下的东西被认为是纯文本.
在加载到浏览器之前,php解释器需要解析php的东西.这通常是通过运行支持php的Web服务器来完成的 - 比如Apache.
结帐XAMPP可以快速入门
XAMPP - http://www.apachefriends.org/en/xampp.html