title: Singleton to factory in PHP
body: <p>There are many topics about this already, but I have not a clear picture of why factory patterns are better practice than Singleton.</p>
  
  <p><strong>An example</strong></p>
  
  <pre><code>class MySingleton {
   public static function numberByWhat( $number ) {
     return $number + 100;
   }
   public static function someCharacters( $string ) {
     return $string + 'abc';
   }
  }
  
  class MyOtherSingleton {
    public static function getImage( $url ) {
      return '&lt;img src="' . $url . MySingleton::numberByWhat( $50 ) . '"&gt;';
    }
    public static function getTextById( $id ) {
      if( $id == 3 ) {
        return 'this is my text' . MySingleton::someCharacters( 'Yeah' );
      }
    }
  }
  
  function run() {
    echo MyOtherSingleton::getImage( 'http://www.example.com/image.png' );
    echo MyOtherSingleton::getTextById( 3 );
  }
  
  run();
  </code></pre>
  
  <p>So there we have 2 classes and a function. When I <code>run()</code> I start a function in the second class. Inside the functions in the second class there are calls to the first class.</p>
  
  <ul>
  <li>How would this look like as a factory pattern?</li>
  <li>Why is it better as a factory pattern?</li>
  </ul>