method chained in class with static methods

Asked

Viewed 101 times

0

Good afternoon to all!!! How do I create a chained method, being it a static method? example:

echo class::mymethod->$variable;

Thank you

  • define it as Static instead of putting public/private in the variable declares it in class as Static and calls class::meumetodo::$variable

1 answer

0

Copy this and glue and see how it works, keep doing the tests.

class Test
{
    public static $attr = "Hello";
    public static function testa(){
        echo "Olá eu sou o testa";
        return new static();
    }
}
$ola = Test::testa()::$attr;
var_dump($ola);

The new static() returns the class Test

Browser other questions tagged

You are not signed in. Login or sign up in order to post.