title: How can I execute a block of code exactly once in PHP?
body: <p>I have one main.php file with a class definition. Other php files use this main.php file </p>
  
  <pre><code>//main.php
  
  &lt;?php
  
  class A{
  
  
  }
  
  //I want to execute the following statements exactly once    
  
  $a = new A();
  /*
  Some code 
  */
  
  
  ?&gt;
  </code></pre>
  
  <p>I use main.php in other php files like</p>
  
  <pre><code>//php1.php
  &lt;?php
  require_once("main.php");
  
  $b = new A();
  
  /* 
  Some code
  */
  
  ?&gt;
  
  //php2.php
  &lt;?php
  require_once("main.php");
  
  $b = new A();
  
  /* 
  Some code
  */
  
  ?&gt;
  </code></pre>
  
  <p>Is there any statement in PHP like execute_once()?
  How do I solve this?</p>