How can I execute a block of code exactly once in PHP?

Posted by Jack on Stack Overflow See other posts from Stack Overflow or by Jack
Published on 2010-04-30T09:05:51Z Indexed on 2010/04/30 9:07 UTC
Read the original article Hit count: 162

Filed under:

I have one main.php file with a class definition. Other php files use this main.php file

//main.php

<?php

class A{


}

//I want to execute the following statements exactly once    

$a = new A();
/*
Some code 
*/


?>

I use main.php in other php files like

//php1.php
<?php
require_once("main.php");

$b = new A();

/* 
Some code
*/

?>

Is there any statement in PHP like execute_once()? How do I solve this?

© Stack Overflow or respective owner

Related posts about php