How to use headers_sent($filename, $linenum) in php?

I’m new to PHP, i wrote this:

<?php
header("Content-type: application/json");
flush();
// Note that $filename and $linenum are passed in for later use.
// Do not assign them values beforehand.
if (!headers_sent($filename, $linenum)) {
    header('Location: http://www.example.com/');
    exit;

// You would most likely trigger an error here.
} else {

    echo "Headers already sent in $filename on line $linenumn" .
          "Cannot redirect, for now please click this <a " .
          "href="http://www.example.com">link</a> insteadn";
    exit;
} 

And the output is:

Headers already sent in  on line 0
Cannot redirect, for now please click this <a href="http://www.example.com">link</a> instead

As you can see, there is an empty string instead of the file name and the line is 0. How can I get the file name and line number where the headers were sent?