Object Oriented PHP

<?php
class Box {
    var $contents;

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

    function get_whats_inside() {
        return $this-&gt;contents;
    }
}
?>

      

I am reading an OO tutorial. I'm familiar with PHP and the OO concept, but it's still a tough fight most of the time! However, the above code returns the error "Unexpectedly also on line 7". I can't find anyone else having problems with the tutorial. I am running MAMP with php version 5.2.5. Does anyone have any idea?

-1


source to share


3 answers


It should read the content of $ this-> instead of $ this- & gt content



+5


source


I think it should be

$this->contents = $contents;
return $this->contents;

      

instead



$this-&gt;contents = $contents;
return $this-&gt;contents;

      

It seems that some HTML code was involved ...

0


source


Somehow your code was HTML coded.

Symbols "&" must be ">"

0


source







All Articles