fork(1) download
  1. <?php
  2. namespace Lottery;
  3. class Lotto {
  4. protected $lots;
  5. public function __construct($lots = [])
  6. {
  7. $this->lots = $lots;
  8. }
  9. public function draw() {
  10. return array_shift($this->lots);
  11. }
  12. }
  13.  
  14. namespace BallotGuy;
  15. use Lottery\Lotto;
  16. /**
  17.  * initialize lotto object
  18.  */
  19. $lotto = new Lotto([313328804459,
  20. 159078851698,
  21. 226414688415,
  22. 380287830671,
  23. 301815692106,
  24. 2991355110,
  25. ]);
  26.  
  27. echo "Drawn: " . $lotto->draw()."\n";
  28. echo "Writing lotto to file. Ending script(j/k)\n";
  29. $saved = serialize($lotto);
  30. //file_put_contents('ballots.txt',$saved);
  31. /**
  32.  * setting to null to emulate script ending
  33.  */
  34. $lotto = null;
  35.  
  36. echo "Loading lotto from file\n";
  37. //$saved = file_get_contents('ballots.txt');
  38. $lotto = unserialize($saved);
  39.  
  40. echo "Drawn: ". $lotto->draw()."\n";
  41.  
  42. var_dump($lotto);
Success #stdin #stdout 0.04s 23080KB
stdin
Standard input is empty
stdout
Drawn: 313328804459
Writing lotto to file. Ending script(j/k)
Loading lotto from file
Drawn: 159078851698
object(Lottery\Lotto)#1 (1) {
  ["lots":protected]=>
  array(4) {
    [0]=>
    int(226414688415)
    [1]=>
    int(380287830671)
    [2]=>
    int(301815692106)
    [3]=>
    int(2991355110)
  }
}