I thought i had a bug in my code but by isolating the problem i found out some 'weird' behaviour of error_log() inside a switch case.
I added some error_log for debugging, but then wehenever i was running throught the switch, the error_log would always be triggered even if the call was made outside of the valid case.
Here the exact part of my code that made me find out this wierdness:
switch($LLTP->request()){
case 'json':
/* some code commented out for debug here */
error_log('json');
echo 'json';
break;
default:
/* some code commented out for debug here */
error_log('html');
echo 'html';
break;
}
the request method is plain and simple and return a string like 'json','html','ajax'
etc..
public function request(){
return $this->requests;
}
so if the switch is html, the default kick in and i get the expepted results:
echoing 'html' (expected)
errorlog 'html' (expected)
BUT when i run it with the 'json' switch, i get the expected 'json' on screen and inside the error_log, but i also get the 'html' error entry (without the echo).
echoing 'json' (expected)
errorlog 'json' (expected)
errorlog 'html, referer: https://www.example.com/home.json' (unexpected)
Is this normal behavior? Fisrt time i notice it and if i try to reproduce the 'weirdness' with another sample code:
$vv='json';
switch($vv){
case 'json':
echo 'json';
error_log('json');
break;
default:
echo 'html';
error_log('html');
break;
}
i get, (in the errorlog)
[error] json (expected)
[error] json, referer: http://www.example.com/home.json (unexpeted as it's the second entry in the log)
i'm lost, there something i don't understand or expected results is not what I expected.
PS: i don'T output the errors on the page, i only log errors in the logs. if this had anything to do with it o.O