3v4l.org

run code in 300+ PHP versions simultaneously
<?php class parentUserId { private $parentId = ''; function __construct($childid) { // convert given long int into binary it must be 64 bit long $binary = $this->dec2bin_long($childid); //trim first 16 char $binary = substr($binary, 0, 16); //add '0' in the right side upto string length get 64 $binary = str_pad($binary, 64, 0, STR_PAD_RIGHT); //Convet new binary into decimal $this->parentId = $this->bin2dec_long($binary); } public function getParentId() { return $this->parentId; } private function dec2bin_long($decimal_i) { bcscale(0); $binary_i = ''; do { $binary_i = bcmod($decimal_i, '2') . $binary_i; $decimal_i = bcdiv($decimal_i, '2'); } while (bccomp($decimal_i, '0')); return str_pad($binary_i, 64, 0, STR_PAD_LEFT); } private function bin2dec_long($binary_i) { bcscale(0); $decimal_i = '0'; for ($i = 0; $i < strlen($binary_i); $i++) { $decimal_i = bcmul($decimal_i, '2'); $decimal_i = bcadd($decimal_i, $binary_i[$i]); } return($decimal_i); } } $obj = new parentUserId("4335559066275177789"); echo $obj->getParentId(); ?>
Output for 5.5.24 - 5.5.28, 5.5.31 - 5.5.33, 5.5.35, 5.6.8 - 5.6.12, 5.6.16 - 5.6.19, 5.6.21 - 5.6.28, 7.0.0 - 7.0.4, 7.0.6 - 7.0.20, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.32, 8.0.0 - 8.0.12, 8.0.14 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.7
4335559066274234368
Output for 7.0.5, 7.3.32 - 7.3.33, 7.4.33, 8.0.13
Fatal error: Uncaught Error: Call to undefined function bcscale() in /in/jgpE3:23 Stack trace: #0 /in/jgpE3(9): parentUserId->dec2bin_long('433555906627517...') #1 /in/jgpE3(45): parentUserId->__construct('433555906627517...') #2 {main} thrown in /in/jgpE3 on line 23
Process exited with code 255.
Output for 5.5.29 - 5.5.30, 5.5.34, 5.6.13 - 5.6.15, 5.6.20
Fatal error: Call to undefined function bcscale() in /in/jgpE3 on line 23
Process exited with code 255.

preferences:
196.57 ms | 402 KiB | 198 Q