3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Test { public static function validateUPCA($value) { $upc = strval($value); $stringLength = strlen($upc); if($stringLength < 12 || $stringLength > 13 || intval($upc)==0) { return false; } $odd_sum = 0; $even_sum = 0; for($i = 0; $i < $stringLength - 1; $i++) { if($i % 2 === 1) { $even_sum += $upc[$i]; } else { $odd_sum += $upc[$i]; } } if ($stringLength == 12) { // UPC-A format. Odd Sum * 3 $total_sum = $even_sum + $odd_sum * 3; } else { // EAN format. Even Sum * 3 $total_sum = $odd_sum + $even_sum * 3; } $modulo10 = $total_sum % 10; $check_digit = $modulo10 == 0 ? 0 : 10 - $modulo10; return $upc[$stringLength - 1] == $check_digit; } } $value = 840018115309; $res = Test.validateUPCA($value); echo "res: $res\n";
Output for git.master, git.master_jit, rfc.property-hooks
Fatal error: Uncaught Error: Undefined constant "Test" in /in/irZ9r:47 Stack trace: #0 {main} thrown in /in/irZ9r on line 47
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
48.5 ms | 401 KiB | 8 Q