Hi all,
here is a function that I was asked to fix for a quizz for a job interview, they replied saying I fixed 3/4 known errors but did not tell me what the fourth error is.
The errors I found
(1)return $check out of scope
(2)missing ";" at end of this line $check = ($s2 << 16) | $s1
(3)global $BASE not within function scope
(4)$query = $_GET['q'] needs a isset() to check if indeed it is set
Basically I made a class and ditched the function, by using class vars I got around $check and $BASE and of course the ";" was inserted but I am stumped on the other error? can you see it?
BBK
CODE BELOW EXACT AS THE QUIZZ
<?php
global $BASE;
$BASE = 65517; // largest prime smaller than 65536
function check32($data) {
$s1 = 1;
$s2 = 0;
for ($n = 0; $n < strlen($data); $n++) {
$s1 = ($s1 + ord($data[$n])) % $BASE;
$s2 = ($s2 + $s1) % $BASE;
}
$check = ($s2 << 16) | $s1
return $check;
}
$query = $_GET['q'];
$check = check32($query);
echo "check value for the phrase \"$query\" is
$check";
?>