How to use add_action(‘wp_ajax_[action name]’,…) for a specific page with condition?

As foo is a static function you don’t need to specify the object, so you can use it outside the condition to correctly load it like this :

 public function __construct(){
    if( isset( $_GET["page"] ) && $_GET["page"] === 'edit-foo' ){
        add_action( 'admin_init', array($this, 'init') );
    }
    add_action('wp_ajax_foo',array( 'MyPlugin/Classes/MyClassWithFooFunction', 'foo' ) );
 }

 init(){
     ... <- initalize $this->editable_item->item
 }

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)