tags:

views:

191

answers:

5

I have seen this at a lot of place but have never understood it's meaning or working... for example:

// Registry
$registry = new Registry();

// Loader
$loader = new Loader($registry);
$registry->set('load', $loader);

If someone can elaborate this, I will be very greatful... thanks in advance...

+8  A: 

That calls a method on an instance of a class or accesses a field of an instance of a class. You may find this page useful.

icktoofay
it's like registry.set() in java, ya?
pxl
@pxl: It's like `.` in java.
Cam
+3  A: 

Its use is in object oriented programming. Consider the following:

class myclass {

    public $x;

    private $y;

    public function get_y () {
        return $this->y;
    }

    public function __construct ($new_x, $new_y) {
        $this->x = (int)$new_x;
        $this->y = (int)$new_y;
    }

}

$myobject = new myclass(5, 8);

echo $myobject->x; // echoes '5';

echo "\n";

echo $myobject->get_y(); // echoes '8'

echo $myobject->y; // causes an error, because y is private

You see how it is used to refer to the properties of an object (the variables we specified in the class definition) and also the methods of the object (the functions). When you use it in a method, it can point to any property and any method, but when used outside the class definition, it can only point to things that were declared "public".

Hammerite
A: 

This is heritage from C++, an access to member (method or attribute) by pointer.

For more C++ operators look here in wikipedia

João
A: 

// Registry $registry = new Registry();

// Loader $loader = new Loader($registry); $registry->set('load', $loader);

Here $registry->set('load', $loader); is the call to the function set('load',$loader), which is is defined in Registry Class.

Also $registry is the instance or object of Registry() Class. Hence using this object, set() function of Registry Class is called.

Neeraj
A: 

thanx a lot guyz... u've helpd me a lot.

mas2040