2

fellow members and visitors.

Please imbue me of your knowledge and allow me to be enlightened by your expertise by answering this question or providing me a path of exploration.

My simple mind cannot has exhausted the possibilities it was aware and would really like to begin to understand what to do in such a situation should it arise again.

Everything begins with a :

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /path/to/site/wp-content/themes/theme_name/inc/general/class-Upbootwp_Walker_Nav_Menu.php:125) in /path/to/site/wp-content/plugins/wp-php-console/includes/class-wp-php-console.php on line 142

Here is the exact ubootwp_Walker_Nav_menu.php class for reference.

I am used to having a precise line number in these kind of error but this time, I get no such indicator (I just get the last line, but there's nothing there except the end of the class.

From my understanding, something in that class instantiate a session and when the Worpdress php console plugin try to do it, it crashes as headers were already sent by that class.

I did add the following

  error_reporting(E_ALL);
  ini_set('display_errors', 'On');

to get the error statement, as I would previously only get a 'error 500'.

I cannot see anything wrong with that class (no obvious echo, print, ob_start). Does some of you have any clue on how I would go in trying to find the root cause of it ?

Any insight will be appreciated.

edit:

  • ubootwp_Walker_Nav_menu.php is a UTF-8 file (No BOM)

  • No hidden characters or anything before php opening tag.

  • No php closing tag at the end of the file
  • No echo,ob_start,print or anything obvious that I can see that would initiate a session.

Thoughts: The error message explicitly states that the error occurs in the php console plugin (which effectively wants to start a session) because the ubootwp_Walker_Nav_menu.php has created the session. Is it possible that the error message is not accurate or does that unequivocaly means that this class is the error ?

Edit 2:

Actually, I thought it was not relevant but I had another notice before the header sent which was:

Strict Standards: Declaration of Upbootwp_Walker_Nav_Menu::start_lvl() should be compatible with Walker_Nav_Menu::start_lvl(&$output, $depth = 0, $args = Array) in /home3/i8h1o2r7/public_html/dev/wp-content/themes/axial/inc/general/class-Upbootwp_Walker_Nav_Menu.php on line 130

This was very relevant to the problem as this was the cause of the "header sent". I fixed the declaration from the class which was not causing an issue before and it fixed the PHP console plugin "session already created" issue from the initial message.

Sage Pourpre
  • 9,932
  • 3
  • 27
  • 39
  • 2
    Possible duplicate of [How to fix "Headers already sent" error in PHP](https://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php) – M. Eriksson Aug 08 '17 at 22:13
  • 1
    Check that there's no space before any opening tag:`` at the end of any php-only files, since a space, or a line break after it, will count as an output. Other than that, it's _impossible_ for us to be able to help you with the issue since we have _no idea_ what the code looks like. – M. Eriksson Aug 08 '17 at 22:16
  • Thanks. I had already done that reading other similar answers... or so I thought. Actually, looking through your reference, I saw something I had missed previously: Output can be unintentional and cause by previous error messages or notices. I had an error before this one which I mistakenly took for a simple no consequence warning about "strict standard" in one of the functions. It was actually causing the headers to be sent even with display_error to false and therefore that was the source of the initial question. thank you. – Sage Pourpre Aug 09 '17 at 03:10

2 Answers2

0

The session has to start before ANY html has been sent to the browser. You can turn on output buffering but, it's going to cause problems if run on a server without output buffering enabled ... Doesn't WP start a session anyway?

  • Not sure how or when Wordpress does it but it doesn't mind a plugin do do it in any case. I had a simple warning about "strict standard" before the fatal error and I thought it unrelated to the main problem and omitted to mention it but it appears it was the reason why the headers were sent. – Sage Pourpre Aug 09 '17 at 03:16
  • Awesome Possum! Seems that you've sorted it out then! – Dallas Price Aug 10 '17 at 21:14
0

I found the solution to this problem from Magnus comment reference to another similar question. In my particular case, the header were sent by another notice that was caused by a signature mismatch and outputting headers early.

Strict Standards: Declaration of Upbootwp_Walker_Nav_Menu::start_lvl() should be compatible with Walker_Nav_Menu::start_lvl(&$output, $depth = 0, $args = Array) in /home3/i8h1o2r7/public_html/dev/wp-content/themes/axial/inc/general/class-Upbootwp_Walker_Nav_Menu.php on line 130

Once that specific error was fixed, headers were not outputted anymore and the second error (initial question) vanished completely.

Sage Pourpre
  • 9,932
  • 3
  • 27
  • 39