title: Synchronized block in php 7
body: <p>i come from a java background where there were synchronized blocks:</p>
  
  <blockquote>
    <p>The "Synchronized" keywords prevents concurrent access to a block of
    code or object by multiple Threads.</p>
  </blockquote>
  
  <p>example code in java:</p>
  
  <pre><code>public void addName(String name) {
      synchronized(this) {
          lastName = name;
          nameCount++;
      }
      nameList.add(name);
  }
  </code></pre>
  
  <p>Now this example highlights a fundamental difference in php and java (correct me if i am wrong). But a singleton or shared class does not exist in php. So the given example of the java code makes a lot of sense when using as a singleton. Thus having a shared object between requests. Now this does not, sadly, seem to exist for php, a major disadvantage obviously. But to do it the php way, that would eventually be writing the name count into a file or database, thus having shared data between requests that way (a lot slower obviously). But the problem would be the same: if 2 requests increase the name count at the exact same time, it will be one too little.</p>
  
  <p>Now the first question: does something similar exist for php 7? that is, the synchronized block</p>
  
  <p>Now i am not sure if in php 7 the word thread really applies to what I am worried about. Is a thread in php considered to be as well a seperate call to a php file lets say <code>foo.php</code> that is, if I access <code>foo.php</code> at the same time twice, will the synchronized block if it exists, be executed only one after another, or do I have to create a proper php thread by extending the class <code>Thread</code> and only then it counts as thread?</p>