fork download
  1. <?php
  2.  
  3. // your code goes here
  4. class single {
  5. public static function kansu() {
  6. static $singleton;
  7. if(!isset($singleton)) {
  8. $singleton=new single();
  9. }
  10. return $singleton;
  11. }
  12. private function __constructor() {
  13. // nop
  14. }
  15. }
  16.  
  17. $hensu1 = single::kansu();
  18. $hensu2 = single::kansu();
  19.  
  20. if($hensu1 === $hensu2) {
  21. print "一致する";
  22. } else {
  23. print "一致しない";
  24. }
  25.  
Success #stdin #stdout 0.02s 23628KB
stdin
Standard input is empty
stdout
一致する