Hello all,
I’ve noticed that since the latest version, inline PHP header() calls inside squelettes/template.html files do not work anymore as before.
I’ve moved the code to pipelines executed before the template even loads (the right way alas).
BUT: I still wanted to point out that the new compiler extracts header() calls no matter where they are, even inside if.
if(false){
header("Location: /");
}
Will be extracted, even if it would never evaluate.
It’s evaluated the same as
if(true){
header("Location: /");
}
or
header("Location: /");
I agree that it’s better to not put redirect headers in SPIP templates, but it would be nice to provide a warning or a mitigation.
Would any of these be a good solution?
- log an error at the template level whenever a header() is found in squelettes, and notify that this behavior is not only deprecated but unstable: it does not behave logically. Inform that the solution is to either use #HEADER at the top of the file, or use redirige_par_entete() when it’s a redirect.
- If there are other things that should never be in template files (exit calls maybe?), also log or throw an error at the template
What do you think?