title: PHP constructors and static functions
body: <p>I'm a bit confused on how constructors work in PHP.</p>
  
  <p>I have a class with a constructor which gets called when I instantiate a new object.</p>
  
  <pre><code>$foo = new Foo($args);
  </code></pre>
  
  <p><code>__construct($params)</code> is called in the class <code>Foo</code> and it executes the appropriate initialization code.</p>
  
  <p>However when I use the class to call a static function, the constructor is called again.</p>
  
  <pre><code>$bar = Foo::some_function(); //runs the constructor from Foo
  </code></pre>
  
  <p>This causes the constructor to execute, running the object initialization code that I intended only for when I create a new <code>Foo</code> object.</p>
  
  <p>Am I missing the point of how constructors work? Or is there a way to prevent <code>__construct()</code> from executing when I use the class to make static function calls?</p>
  
  <p>Should I use a "factory" function instead to do the object initialization? If so, what's the point of the constructor then?</p>
  
  <p>::EDIT::
  I have a form where users can upload photos to an album (create_photo.php) and an area where they can view the album (view_photos.php). Upon form submit:</p>
  
  <pre><code>$photo = new Photo($_FILES['photo'], $_POST['arg1'], ect..);
  </code></pre>
  
  <p>The Photo constructor creates and saves the photo. However in view_photo.php, when I call:</p>
  
  <pre><code>$photo = Photo::find_by_id($_POST['id']) //user-defined function to query database
  </code></pre>
  
  <p>This is causing Photo's constructor to run!</p>