如何获取函数的变量

I have a WordPress widget but i don't know how to get a $title variable to my my_custom function below the class from the form function. I tried this newbie solution but not working

class My_Widget extends WP_Widget {

public function __construct() {

}

public function widget( $args, $instance ) {

}

public function form( $instance ) {

         if ( isset( $instance[ 'title' ] ) ) {
        $title = $instance[ 'title' ];
     }
     else {
     $title = 'New title';

}
    }
public function update( $new_instance, $old_instance ) {

}
    }

    function my_custom(){

     $my_title = $instance[ 'title' ];
      echo $my_title;

    }

first make an object of class and then get the class variable

class My_Widget extends WP_Widget {
public $mytitle;
public function __construct() {

}

public function widget( $args, $instance ) {

}

public function form( $instance ) {

         if ( isset( $instance[ 'title' ] ) ) {
        $this->mytitle = $instance[ 'title' ];
     }
     else {
    $this->mytitle = 'New title';

}
    }
public function update( $new_instance, $old_instance ) {

}
    }

    function my_custom(){
     $widgetobj=new My_Widget();
     $my_title = $widgetobj->mytitle;
      echo $my_title;

    }