Skip to content

Instantly share code, notes, and snippets.

@rodrigosetti
Last active August 29, 2015 14:02
Show Gist options
  • Save rodrigosetti/b622ad72c212de760318 to your computer and use it in GitHub Desktop.
Save rodrigosetti/b622ad72c212de760318 to your computer and use it in GitHub Desktop.

PHP have different namespaces for methods and value attributes.

<?php

class C {
    function d() {
        return "d-value";
    }
}

class B {

    public $c;

    function __construct() {
        $this->c = new C;
    }

    function c() {
        return "c-value";
    }
}

class A {

    public $b;

    function __construct() {
        $this->b = new B;
    }

    function b() {
        return "b-value";
    }
}
                                                                                  
$a = new A;

echo $a->b() . PHP_EOL;
echo $a->b->c() . PHP_EOL;
echo $a->b->c->d() . PHP_EOL;

--

b-value
c-value
d-value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment