diff --git a/README.md b/README.md index 14ccdc9..8f66f3e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Mapcode Library for PHP -Copyright (C) 2014-2020 Stichting Mapcode Foundation (http://www.mapcode.com) +Copyright (C) 2014-2022 Stichting Mapcode Foundation (http://www.mapcode.com) ---- @@ -44,6 +44,10 @@ limitations under the License. ## Version History +### 2.2.3 + +* Updated to support PHP version 8.1.4 (thanks, Bert Hooyman). + ### 2.2.2 * Fixed PHP errors for new version of PHP. diff --git a/mapcode_api.php b/mapcode_api.php index ccd9718..88e5d45 100644 --- a/mapcode_api.php +++ b/mapcode_api.php @@ -1,7 +1,7 @@ lon; @@ -961,7 +961,7 @@ function decodeAutoHeader($input, $extensionchars, $m) } $value *= (961 * 31); $triple = decodeTriple(substr($input, strlen($input) - 3)); - if ($triple == 0) { + if (!$triple) { return new MapcodeZone(); } for (; Codex($m) == $codexm; $m++) { @@ -1239,7 +1239,7 @@ function to_ascii($str) } $p = strrpos($result, ' '); if ($p === false) $p = 0; else $p++; - if ($result[$p] == 'A') { + if ((strlen($result)) && ($result[$p] == 'A')) { $result = substr($result, 0, $p) . aeu_pack(aeu_unpack(substr($result, $p))); } return $result; @@ -1454,7 +1454,7 @@ function decode($mapcodeString, $territory = -1) } else { return master_decode($mapcodeString, $contextTerritoryNumber); } - return 0; + return null; } function encodeSixWide($x, $y, $width, $height) @@ -1783,7 +1783,7 @@ function mapcoderEngine($enc, $tn, $getshortest, $isrecursive, $state_override, if (is_numeric($tn) && $tn >= 0 && $tn <= $uptoRun) { $fromRun = $tn; $uptoRun = $tn; - } else if ($GLOBALS['redivar']) { + } else if (array_key_exists('redivar', $GLOBALS)) { $use_redivar = 1; $HOR = 1; $i = 0; // pointer into redivar @@ -1949,4 +1949,4 @@ function encodeShortestWithPrecision($latitudeDegrees, $longitudeDegrees, $preci function encodeShortest($latitudeDegrees, $longitudeDegrees, $territory = -1) { return encodeShortestWithPrecision($latitudeDegrees, $longitudeDegrees, 0, $territory); -} \ No newline at end of file +} diff --git a/mapcode_library_php.doc b/mapcode_library_php.doc index de58677..01d41cf 100644 Binary files a/mapcode_library_php.doc and b/mapcode_library_php.doc differ diff --git a/sample.php b/sample.php index 43ea735..35431cc 100644 --- a/sample.php +++ b/sample.php @@ -34,7 +34,11 @@ echo '

Mapcode PHP version ' . mapcode_phpversion . ' example

'; - $input = trim($_REQUEST["s"]); + if (array_key_exists('s', $_REQUEST)) { + $input = trim($_REQUEST["s"]); + } else { + $input = NULL; + } if ($input != NULL) { //$input = utf8_decode(mb_convert_encoding($input,"utf-8" )); if (strpos($input, ',') !== false) // contains a comma, so assume coordinates @@ -60,7 +64,7 @@ echo ' (romanized as ' . $asc . ')'; } $d = decode($input); - if ($d == 0) { + if (!$d) { echo '
is not a valid mapcode
'; if (strpos($input, ' ') === false) { echo '(did you include the territory?)
'; diff --git a/unittest/unittest.php b/unittest/unittest.php index 096067a..0b5c1f1 100644 --- a/unittest/unittest.php +++ b/unittest/unittest.php @@ -40,8 +40,8 @@ function progress(id, x, total) { include 'test_territories.php'; include 'test_encodes.php'; -ini_set('max_execution_time', 300); -set_time_limit(300); +ini_set('max_execution_time', 1200); +set_time_limit(1200); echo "Mapcode Unittest version 2.2
"; echo "Mapcode PHP version " . mapcode_phpversion . "
"; @@ -167,7 +167,7 @@ function test_encode_decode($str, $y, $x, $localsolutions, $globalsolutions) $str = $r[$i]; // check if every solution decodes $p = decode($str); - if ($p == 0) { + if (!$p) { $GLOBALS['nrErrors']++; echo '*** ERROR *** decode(' . $str . ') = no result. expected ~(' . number_format($y, 14) . ' . ' . number_format($x, 14) . ')
'; } else { @@ -340,7 +340,12 @@ function test_encodes() while ($t[$n * 5] !== false) $n++; // executed (optionally, from "start" parameter) - $i = intval($_GET["start"]) - 1; + if (array_key_exists("start", $_GET)) { + $i = intval($_GET["start"]) - 1; + } else { + $i = 0; + } + if ($i < 0) $i = 0; $nextlevel = $i; while ($i <= $n) { @@ -419,7 +424,7 @@ function territory_code_tests() "USA", -1, "US OTHER TEXT", "USA", -1, " US OTHER TEXT ", "US-CA", -1, "US-CA", - "US-CA", -1 - 1, "US-CA OTHER TEXT", + "US-CA", -1, "US-CA OTHER TEXT", "US-CA", -1, "USA-CA", "RU-TT", -1, "RUS-TAM", -1, -1, "RUS-TAMX", @@ -498,7 +503,11 @@ function test_corner_encodes() echo '
Edge encode/decode tests 0%
'; { - $i = intval($_GET["edge"]); + if (array_key_exists("edge", $_GET)) { + $i = intval($_GET["edge"]); + } else { + $i = 0; + } if ($i > 0) $GLOBALS['next_corner_to_test'] = $i; while (test_corner_encodes()) ; }