You should provide the implementation of set_username() as well. This script prints 'admin = admin', which is expected:
<?php
final class Blog
{
private static $username;
private function __construct() {}
public static function admin()
{
if (empty(self::$username) === false)
{
exit('admin = ' . self::$username);
}
echo 'we got here';
}
public static function set_username($username)
{
self::$username = $username;
}
}
Blog::set_username('admin');
Blog::admin();
However, I suspect that you actually expect it to print 'we got here', since we usually write tests that we expect to "pass" by not exiting rather than writing tests that "fail" by exiting when the condition is as we expect.
EDIT:
In case I was not clear, I am saying that your statement that "this code shouldnt shouldn't exit but it does" is wrong to begin with. Rather, the code should exit and print 'admin = admin' and it does. The reason is that if self::$username is not empty, then empty(self::$username) is false. Since false === false is true, the script exits at that point.