Exact same code passes a lint check ‘php -l’ on php 5.3.13 (server) but not on php 5.3.12 (local). Is this a result of my local configuration and something I could change or should I? I can rewrite the else below using a printf() for example, but just curious.
PHP Parse error: syntax error, unexpected T_EXIT, expecting T_FUNCTION
function wp_custom_redirect($url) {
if( ! headers_sent() )
{
wp_redirect($url);
}
else
{
?>
<script>
self.location.href = '<?php echo $url; ?>';
</script>
<?php
}
exit();
}
updated: the line with the exit(); (T_EXIT) is the line with the error.
I can rewrite the else to look like this (see below) and lint passes on my local machine. What I’m trying to determine is why it fails when it is valid php, and I suspect it’s some php.ini configuration. I’m just not sure where yet.
else
{
printf( '<script>self.location.href = "%s";</script>', $url );
}
solved it was a previous example of this, but a <? used instead of a <?php and on my local server configuration, the short_tags were Off, no idea why the lint kept going until much later in the code
The configuration was indeed the issue, as it was a short_tags = Off setting on my local php.ini. I didn’t catch it earlier in a function much earlier than the one I posted, but the line number didn’t help and I’m not entirely sure why the lint didn’t indicate the short_tag instead of the T_EXIT.