How can I execute a block of code exactly once in PHP?
- by Jack
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?