3v4l.org

run code in 300+ PHP versions simultaneously
<?php define ("FNV_prime_32", 16777619); define ("FNV_prime_64", 1099511628211); define ("FNV_prime_128", 309485009821345068724781371); define ("FNV_offset_basis_32", 2166136261); define ("FNV_offset_basis_64", 14695981039346656037); define ("FNV_offset_basis_128", 144066263297769815596495629667062367629); /* * The core of the FNV-1 hash algorithm is as follows: * * hash = offset_basis * for each octet_of_data to be hashed * hash = hash * FNV_prime * hash = hash xor octet_of_data * return hash * * Source: http://www.isthe.com/chongo/tech/comp/fnv/ */ /* * Example Java implementation: * * long fnv(byte[] buf, int offset, int len, long seed) * { * for (int i = offset; i < offset + len; i++) * { * seed += (seed << 1) + (seed << 4) + (seed << 7) + (seed << 8) + (seed << 24); * seed ^= buf[i]; * } * return seed; * } * * `Source: http://www.getopt.org/ - FNV1 Hash */ function fnvhash_fnv1($txt) { $buf = str_split($txt); $hash = FNV_offset_basis_32; foreach ($buf as $chr) { $hash = 0x0ffffffff & ($hash * FNV_PRIME_32); $hash ^= ord($chr); } $hash = $hash & 0x0ffffffff; return $hash; } var_dump(fnvhash_fnv1("test")); var_dump(fnvhash_fnv1("tess"));
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Uncaught Error: Undefined constant "FNV_PRIME_32" in /in/8DdHT:45 Stack trace: #0 /in/8DdHT(53): fnvhash_fnv1('test') #1 {main} thrown in /in/8DdHT on line 45
Process exited with code 255.
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
Warning: Use of undefined constant FNV_PRIME_32 - assumed 'FNV_PRIME_32' (this will throw an Error in a future version of PHP) in /in/8DdHT on line 45 Warning: A non-numeric value encountered in /in/8DdHT on line 45 Warning: Use of undefined constant FNV_PRIME_32 - assumed 'FNV_PRIME_32' (this will throw an Error in a future version of PHP) in /in/8DdHT on line 45 Warning: A non-numeric value encountered in /in/8DdHT on line 45 Warning: Use of undefined constant FNV_PRIME_32 - assumed 'FNV_PRIME_32' (this will throw an Error in a future version of PHP) in /in/8DdHT on line 45 Warning: A non-numeric value encountered in /in/8DdHT on line 45 Warning: Use of undefined constant FNV_PRIME_32 - assumed 'FNV_PRIME_32' (this will throw an Error in a future version of PHP) in /in/8DdHT on line 45 Warning: A non-numeric value encountered in /in/8DdHT on line 45 int(116) Warning: Use of undefined constant FNV_PRIME_32 - assumed 'FNV_PRIME_32' (this will throw an Error in a future version of PHP) in /in/8DdHT on line 45 Warning: A non-numeric value encountered in /in/8DdHT on line 45 Warning: Use of undefined constant FNV_PRIME_32 - assumed 'FNV_PRIME_32' (this will throw an Error in a future version of PHP) in /in/8DdHT on line 45 Warning: A non-numeric value encountered in /in/8DdHT on line 45 Warning: Use of undefined constant FNV_PRIME_32 - assumed 'FNV_PRIME_32' (this will throw an Error in a future version of PHP) in /in/8DdHT on line 45 Warning: A non-numeric value encountered in /in/8DdHT on line 45 Warning: Use of undefined constant FNV_PRIME_32 - assumed 'FNV_PRIME_32' (this will throw an Error in a future version of PHP) in /in/8DdHT on line 45 Warning: A non-numeric value encountered in /in/8DdHT on line 45 int(115)
Output for 7.1.0 - 7.1.33
Notice: Use of undefined constant FNV_PRIME_32 - assumed 'FNV_PRIME_32' in /in/8DdHT on line 45 Warning: A non-numeric value encountered in /in/8DdHT on line 45 Notice: Use of undefined constant FNV_PRIME_32 - assumed 'FNV_PRIME_32' in /in/8DdHT on line 45 Warning: A non-numeric value encountered in /in/8DdHT on line 45 Notice: Use of undefined constant FNV_PRIME_32 - assumed 'FNV_PRIME_32' in /in/8DdHT on line 45 Warning: A non-numeric value encountered in /in/8DdHT on line 45 Notice: Use of undefined constant FNV_PRIME_32 - assumed 'FNV_PRIME_32' in /in/8DdHT on line 45 Warning: A non-numeric value encountered in /in/8DdHT on line 45 int(116) Notice: Use of undefined constant FNV_PRIME_32 - assumed 'FNV_PRIME_32' in /in/8DdHT on line 45 Warning: A non-numeric value encountered in /in/8DdHT on line 45 Notice: Use of undefined constant FNV_PRIME_32 - assumed 'FNV_PRIME_32' in /in/8DdHT on line 45 Warning: A non-numeric value encountered in /in/8DdHT on line 45 Notice: Use of undefined constant FNV_PRIME_32 - assumed 'FNV_PRIME_32' in /in/8DdHT on line 45 Warning: A non-numeric value encountered in /in/8DdHT on line 45 Notice: Use of undefined constant FNV_PRIME_32 - assumed 'FNV_PRIME_32' in /in/8DdHT on line 45 Warning: A non-numeric value encountered in /in/8DdHT on line 45 int(115)
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 5.6.28, 7.0.0 - 7.0.20
Notice: Use of undefined constant FNV_PRIME_32 - assumed 'FNV_PRIME_32' in /in/8DdHT on line 45 Notice: Use of undefined constant FNV_PRIME_32 - assumed 'FNV_PRIME_32' in /in/8DdHT on line 45 Notice: Use of undefined constant FNV_PRIME_32 - assumed 'FNV_PRIME_32' in /in/8DdHT on line 45 Notice: Use of undefined constant FNV_PRIME_32 - assumed 'FNV_PRIME_32' in /in/8DdHT on line 45 int(116) Notice: Use of undefined constant FNV_PRIME_32 - assumed 'FNV_PRIME_32' in /in/8DdHT on line 45 Notice: Use of undefined constant FNV_PRIME_32 - assumed 'FNV_PRIME_32' in /in/8DdHT on line 45 Notice: Use of undefined constant FNV_PRIME_32 - assumed 'FNV_PRIME_32' in /in/8DdHT on line 45 Notice: Use of undefined constant FNV_PRIME_32 - assumed 'FNV_PRIME_32' in /in/8DdHT on line 45 int(115)
Output for 4.4.5 - 4.4.9
Fatal error: Call to undefined function: str_split() in /in/8DdHT on line 41
Process exited with code 255.
Output for 4.3.2 - 4.3.11, 4.4.0 - 4.4.4
Fatal error: Call to undefined function: str_split() in /in/8DdHT on line 41
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Call to undefined function: str_split() in /in/8DdHT on line 41

preferences:
234.95 ms | 401 KiB | 343 Q