Logo Questions Linux Laravel Mysql Ubuntu Git Menu

Php sub-methods




I've used php enough to be quite comfortable with it, but recently I've been looking through some MVC frameworks to try and understand how they work, and I've come across a syntax and data structure which I haven't encountered before:

function view($id)   
       $this->Note->id = $id;   

What is the ->id section of this code? Is this a sub-method based off it's parent method? If so, how do I go about writing code to create such a structure? (ie. creating the structure from scratch, not using an existing framework like the above example from cakephp).

like image 777
Richard Avatar asked Feb 11 '11 16:02


1 Answers

The following code demonstrates how one could arrive at the structure you described.


class Note
    public $id = 42;

class MyClass
    public function __construct() {
        // instance of 'Note' as a property of 'MyClass'
        $this->Note = new Note();

    public function test() {
        printf("The \$id property in our instance of 'Note' is: %d\n",

$mc = new MyClass();
like image 85
Jon Nalley Avatar answered Sep 17 '22 10:09

Jon Nalley