面向对象的PHP

Dre*_*rew -1 php

<?php
class Box {
    var $contents;

    function Box($contents) {
        $this-&gt;contents = $contents;
    }

    function get_whats_inside() {
        return $this-&gt;contents;
    }
}
?>
Run Code Online (Sandbox Code Playgroud)

我正在阅读OO教程.我熟悉PHP和OO的概念,但大多数时候它仍然是一场艰难的斗争!但是,上面的代码返回错误"Unexpected&on line 7".我发现其他任何人都没有遇到过本教程的问题.我用PHP版本5.2.5运行MAMP.有人有主意吗?

Vin*_*vic 5

它应该读取$ this-> contents而不是$ this->内容