• Moderator Marius L. J.

    (@clorith)


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

    Example:

    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.

    https://www.ads-software.com/extend/plugins/debug-bar/

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