Error on child themes ojs3.1.1.4: submissions api with a status of 500 when <Child>ThemePlugin.inc.php has spaces or braklines at end

In general it has been a very difficult problem to debug, as it says in the title the error occurs when the main class of the child theme has spaces or line breaks at the end of the file where it is defined (that is, if the index.php of the theme son has spaces or line breaks, no problem). Particularly I do not know how to correct the problem in the source code for future users using a child theme or give a more specific warning so this does not happen. For this I publish this petition (due to my own ignorance).

The easiest way to replicate the error is to add a child theme and in its main class ThemePlugin.inc.php add spaces or line breaks and then go to the page index.php / / submissions, in this there will be a 500 error in the console followed by other errors chained to it.
childthemeerrorlogconsolebrowser

The apache log show some like that:

PHP Fatal error: Uncaught exception ‘RuntimeException’ with message ‘Unexpected data in output buffer. Maybe you have characters before an opening <?php tag?’ in /var/www/html/siteojs/lib/pkp/lib/vendor/slim/slim/Slim/App.php:622\nStack trace:\n#0 /var/www/html/siteojs/lib/pkp/lib/vendor/slim/slim/Slim/App.php(334): Slim\App->finalize(Object(APIResponse))\n#1 /var/www/html/siteojs/lib/pkp/classes/core/APIRouter.inc.php(109): Slim\App->run()\n#2 /var/www/html/siteojs/lib/pkp/classes/core/Dispatcher.inc.php(134): APIRouter->route(Object(Request))\n#3 /var/www/html/siteojs/lib/pkp/classes/core/PKPApplication.inc.php(247): Dispatcher->dispatch(Object(Request))\n#4 /var/www/html/siteojs/index.php(68): PKPApplication->execute()\n#5 {main}\n thrown in /var/www/html/siteojs/lib/pkp/lib/vendor/slim/slim/Slim/App.php on line 622, referer: http:///index.php//submissions

The page of the api in which the error occurs is in the following one (as can be seen in the console if the error is replicated):

http: // /index.php/ / api / v1 / _submissions? status% 5B% 5D = 4 & status% 5B% 5D = 3 & searchPhrase = & count = 20 & offset = 0 & _ = 15493062312

Of course the errors are corrected by erasing the spaces and line breaks of the main class of the child theme, but for others it could be a real headache to get to the source of the problem.

In this repo can find a dummy theme with brakspaces on the main theme class for reply the error.

Hi @LUIS_GERARDO_MANRIQU,

I’m afraid that’s simply the way PHP works – a blank space before the beginning <?php tag, or after the closing ?> tag, will cause problems for later code that tries to send headers. The recommended best practice is not to include closing ?> tags in class files.

Regards,
Alec Smecher
Public Knowledge Project Team