1

I'm trying something new for me:

class bar {
    public function outside(){
        function inside(){
            return "baz";
        }
    } 
}

$foo = new bar();

I want call two functions in one line (some like this):

echo $foo->outside()->inside(); // Fatal error: Uncaught Error: Call to a member function inside() on null 

I thought it would return "baz but not. How I can build this syntax?

Dave
  • 2,764
  • 2
  • 15
  • 27
  • What are you trying to do here? Nested named functions are extremely discouraged. – aynber Sep 28 '21 at 18:51
  • `inside()` would have to be a function of `bar`, and `outside()` would have to return a reference to `$this` for chaining to work like that (or something along those lines). – Tim Lewis Sep 28 '21 at 18:51
  • This is called "fluent", which should give you a keyword for research which will yield lots of examples. – Ulrich Eckhardt Sep 28 '21 at 18:51

0 Answers0