Support » Plugin: Debug Bar » $this is determined as an undefined variable

  • Moderator Marius L. J.


    The debug bar determines $this as an undefined variable when used within a class\function call, but will happily accept &$this without any notices.


    class test_class {
      function make_menu() {
        $page_title = __( 'Page title' );
        $menu_title = __( 'Menu title' );
        $capability = 'read';
        $menu_slog  = 'test-slug';
        $function   = array( $this, 'menu_function );
        add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function );
      function menu_function() {

    The above will create a Notice that “this” isn’t defined, but replace $this with &$this and it will no longer produce this notification.

  • The topic ‘$this is determined as an undefined variable’ is closed to new replies.