使用index.php中的函数,如class-> publicF-> f()

guys lets say we have this class: all i want to do is to use a specific function to do something, think it as a button, but in a way that you have 1 public function and you can execute parts of it!

CLASS DATA {
      public function X() {
           function A() { 
              //do_something
           }
      }
}

and now i'm in the index.php and i want to call the function A() only. i tried $data->X()->A() but nothing i tried $data->X(A()) also nothing

is it possible this?

In the way you've written it, no. Looks to me like you're trying to build something in the way you would a Javascript application. But like Rizier123 points out you could do something like this.

class Foo {
    public function getBar(){
        return new Bar();
    }
}

class Bar {
    public function someFunction() {

    }
}


$foo = new Foo();

$foo->getBar()->someFunction();

Although I'm not entirely sure why you would want to nest things that way when inheriting would be a better route. Something like this:

class Foo extends Bar {

}

class Bar {
    public function someFunction() {

    }
}


$foo = new Foo();

$foo->someFunction();

But I guess you could use the former as a way to pass specific constructor parameters in a consistent manor.

class Foo {
    public function getRainbow(){
        return new Bar('rainbow');
    }
}

class Bar {
    private $type;

    public function __construct($type)
    {
        $this->type = $type;
    }

    public function someFunction() {
        switch($this->type){
            case 'rainbow':
                echo 'All the way across the sky.';
                break;
            default:
                echo 'Boring.';
                break;
        }
    }
}


$foo = new Foo();

$foo->getRainbow()->someFunction();