3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php <?php defined('C5_EXECUTE') or die('Access Denied'); /** * Immutable class for handling numbers with precision. * * Never change the $number or the $precision after the creation of the object. */ class DecimalNumber { private $precision; private $number; /** * Get an instance given a string and a precision * @param string $string The decimal number in string form * @param int $precision The precision of the number * @return DecimalNumber Return new instance */ public static function createWithString($string, $precision = 4) { $me = get_called_class(); $number = new $me; $number->precision = $precision; $number->number = bcadd($string, '0', $precision); return $number; } /** * Perform an addition operation * @param DecimalNumber $number the number to add * @return DecimalNumber Return the sum */ public function add(DecimalNumber $number) { return DecimalNumber::decimalNumberWithString(bcadd($this->number, $number, $this->precision)); } /** * Automagically convert to a string * @return string returns a string containing the value of this DecimalNumber */ public function __toString() { return $this->number; } } $d = DecimalNumber::createWithString('.7'); echo $d->add(DecimalNumber::createWithString('.1');
Output for 5.3.0 - 5.4.21
Parse error: syntax error, unexpected '<' in /in/NeH44 on line 2
Process exited with code 255.