vinkla/hashids

Parsing ERROR?

Drew-Chase opened this issue · 2 comments

Description

I'm attempting to use HashIds in a testing environment and I'm getting a parsing error. I'm not able to use composer, so I'm using Git sub-modules instead

Error

Parse error: syntax error, unexpected ')', expecting variable (T_VARIABLE) in C:\xampp\htdocs\assets\libraries\hashids\src\Hashids.php on line 37

Code

<?php

/* Including the Hashids library. */
require_once realpath(getcwd() . "/../libraries/hashids/src/Hashids.php");

/* Importing the Hashids class from the Hashids namespace. */
use Hashids\Hashids;

/* Creating a new instance of the Hashids class. The first parameter is the salt, which is used to
generate the hash. The second parameter is the minimum length of the hash. */
$hashids = new HashIds("77fd242daa064a2ba4786c7968764e0f", 6);

/* Checking if the `id` parameter is set in the URL. If it is, it will return a JSON object with the
key `key` and the value of the `id` parameter encoded with the Hashids library. */
if (isset($_GET["id"])) {
    return json_encode(["key" => $hashids->encode($_GET["id"])]);
}

/* This is the same as the previous `if` statement, but it checks if the `key` parameter is set in
the URL. If it is, it will return a JSON object with the key `id` and the value of the `key`
parameter decoded with the Hashids library. */
if (isset($_GET["key"])) {
    return json_encode(["id" => $hashids->decode($_GET["key"])]);
}

with a request of:
http://localhost/assets/php/hashids.inc.php?id=5

Please provide a failing test case in a pull request.

You use PHP8 version of the library on PHP7 environment. Please try version 4.1.0 of the library.