public function genMenu($parent_id, $menu_type, $utype, $parent_token=0, $currentpage = 0) {
$stmt = $this->db->prepare("SELECT n.page_id, p.short_name, p.token FROM navigation AS n, pages AS p, user_page_restr AS r WHERE n.parent_id = ? AND r.pg_id=p.id AND n.menu=? AND (r.user_type=? OR r.user_type=0) AND n.page_id=p.id ORDER BY r.order") or die($this->db->error);
$stmt->bind_param("iii", $parent_id, $menu_type, $utype) or die($stmt->error);
$stmt->execute() or die($stmt->error);
$stmt->store_result();
$menu = array();
$stmt->bind_result($menu['id'], $menu['short_name'], $menu['token']) or die($stmt->error);
if ($stmt->num_rows > 0)
echo "\n<ul>\n";
while ($stmt->fetch()) {
echo "<li ";
if ($menu['token']==$currentpage) {
echo 'class="active"';
}
echo ">";
switch ($menu_type) {
case 2:
echo '<a href="?page=' . $parent_token;
echo '&subpage=' . $menu['token'];
echo '">' . $menu['short_name'] . '</a>';
break;
default:
echo '<a href="?page=' . $menu['token'] . '">' . $menu['short_name'] . '</a>';
break;
}
echo "</li>\n\n";
}
if ($stmt->num_rows > 0)
echo "</ul>\n";
$stmt->close();
}

Take a look at this
if ($menu['token']==$currentpage) {
echo 'class="active"';
}
Even if $menu[‘token’] is string and has exact value and $currentpage is 0, if condition returns result true and executes expression inside if (echo 'class="active"';)
Can anyone explain why this occurs?
You have a casting issue. When you compare an integer to a string with the
==operator the string is cast to its integer equivalent, which for a string that does not begin with a digit is 0.The answer depends on what you want to do. If you only want to match a string with a string use the
===operator.If you want an empty string to match 0, you can use
to make sure that the comparison is done string to string rather than the default int to int.