3v4l.org

run code in 300+ PHP versions simultaneously
<?php $rcg = new RandomChar(GenType::Digits_only,10); echo $rcg->generate(); class RandomChar { public $genType; public $size; function __construct($genType,$size) { $this->genType = $genType; $this->size = $size; } function generate() { $generated = ""; switch ($this->genType) { case GenType::Digits_only: for ($index = 0; $index < $this->size; $index++) { $generated = $generated + $this->generateDigitOnly(); } break; default: break; } return $generated; } function generateDigitOnly() { $num_array = array('0','1','2','3','4','5','6','7','8','9'); $rand_keys = array_rand($num_array, 1); return $rand_keys[0]; } } class GenType { const Digits_only = 0; const Letters_Lowercase = 1; const Letters_Uppercase = 2; const Letters_LowerUppercase = 3; const Digits_Lowercase = 4; const Digits_Uppercase = 5; const Digits_LowerUppercase = 6; }
Output for 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
Warning: Trying to access array offset on int in /in/BkEOp on line 31 Fatal error: Uncaught TypeError: Unsupported operand types: string + null in /in/BkEOp:20 Stack trace: #0 /in/BkEOp(3): RandomChar->generate() #1 {main} thrown in /in/BkEOp on line 20
Process exited with code 255.
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29
Warning: Trying to access array offset on value of type int in /in/BkEOp on line 31 Fatal error: Uncaught TypeError: Unsupported operand types: string + null in /in/BkEOp:20 Stack trace: #0 /in/BkEOp(3): RandomChar->generate() #1 {main} thrown in /in/BkEOp on line 20
Process exited with code 255.
Output for 7.4.0 - 7.4.33
Notice: Trying to access array offset on value of type int in /in/BkEOp on line 31 Warning: A non-numeric value encountered in /in/BkEOp on line 20 Notice: Trying to access array offset on value of type int in /in/BkEOp on line 31 Notice: Trying to access array offset on value of type int in /in/BkEOp on line 31 Notice: Trying to access array offset on value of type int in /in/BkEOp on line 31 Notice: Trying to access array offset on value of type int in /in/BkEOp on line 31 Notice: Trying to access array offset on value of type int in /in/BkEOp on line 31 Notice: Trying to access array offset on value of type int in /in/BkEOp on line 31 Notice: Trying to access array offset on value of type int in /in/BkEOp on line 31 Notice: Trying to access array offset on value of type int in /in/BkEOp on line 31 Notice: Trying to access array offset on value of type int in /in/BkEOp on line 31 0
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33
Warning: A non-numeric value encountered in /in/BkEOp on line 20 0
Output for 5.6.0 - 5.6.40, 7.0.0 - 7.0.33
0

preferences:
173.16 ms | 412 KiB | 5 Q