When using debug_backtrace() to check if you're being accessed from another caller, please remember to ask debug_backtrace to only go as far as needed in depth and skip taking the entire debug object as return parameter:
<?php
if (count(debug_backtrace(FALSE, 1)) == 0)
{
// Do something
}
?>