3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace ECommerce { use Exception; class CreditCardValidationException extends Exception { } class CreditCardNumber { private $digits; public function __construct($digits) { $this->digits = $digits; if (!$this->_validate()) { throw new CreditCardValidationException('Checksum failed'); } } private function _validate() { for($i=0,$t=0;$i<16;$i+=2) $t+=(($d=((int)$this->digits{$i}*2))>9?array_sum(array_map('intval',str_split(strval($d)))):$d)+$this->digits{$i+1}; return(bool)($t%10===0); } } } namespace { try { $ccn = new ECommerce\CreditCardNumber('4417123456789113'); } catch (ECommerce\CreditCardValidationException $exception) { echo 'Invalid credit card number'; } finally if (!isset($exception)) { echo 'VALID credit card number'; } }
Output for 5.4.0 - 5.4.25
Parse error: syntax error, unexpected 'if' (T_IF) in /in/SqTIg on line 28
Process exited with code 255.
Output for 5.3.0 - 5.3.28
Parse error: syntax error, unexpected T_IF in /in/SqTIg on line 28
Process exited with code 255.

preferences:
182.54 ms | 1386 KiB | 62 Q