Alex Rivera | Logout

PHP double arrow notation for instances of an class(es)

Asked 2011-07-24T12:42:20.300
10

I would be grateful if someone explained to me the use of double arrow notation in PHP. I suggest is a double classes and instantiation of that classes, but I am not sure. Some examples will be good. Thanks.

Something like this:

$obj->prop->methd();
Edit
Report

1 Answer

2

As long as your method returns an object you can call the methods of that object too, and so on.

So here's an example of how you can chain methods of a class.

<?php
class MyTest {
    public function Hello() {
        echo "Hello ";
        return $this;
    }

    public function World() {
        echo "World!";
    }
}

$h = new MyTest();
$h->Hello()->World();
?>
answered 2011-07-24T12:50:17.163

Your Answer