title: php constructor undefined property
body: <p>For a programm i am working on, i want to create an instance of the imageMachine class (imagmachine.php), from within navi.php. </p>
  
  <p>In Navi.php the following code:</p>
  
  <pre><code>$target_dir = "";
  $target_file = $target_dir . basename($_FILES["fileToUploadName"]["name"]);
  require_once (__ROOT__.'/imagemachine.php');
  $imageMachineSubject = new ImageMachine ($target_dir, $target_file);
  $imageMachineSubject -&gt; saysth();
  </code></pre>
  
  <p>, is supposed to create a new imageMAchine object and call its saysth() method. The parameters are from a form in a ui file.</p>
  
  <p>Within imageMachine, I want to do some stuff with the image obviously, but thats not the issue. For the moment i keep running into a wall, when i simply want the instance to simply safe the params ($target_dir, $target_file) from the constructor, so that i can work with the values in other methods.</p>
  
  <pre><code>&lt;?php
  class ImageMachine {
  
    public $imageFile;
    public $imageExtension;
  
    public function __construct ($target_dir, $target_file)
    {
      $this-&gt;imageFile= $target_file;
  
      echo $imageFile;
      // Undefined variable: imageFile in C:\xampp\htdocs\imagemachine.php on line 12
    }
  
    function saysth (){
      echo ($this-&gt;$imageFile);
      // Undefined property: ImageMachine::$image_file in C:\xampp\htdocs\imagemachine.php on line 17
      // Undefined property: ImageMachine::$  in C:\xampp\htdocs\imagemachine.php on line 17
      echo ($imageFile);
      // Undefined variable: imageFile in C:\xampp\htdocs\imagemachine.php on line 19
      echo $imageFile;
      // Undefined variable: imageFile in C:\xampp\htdocs\imagemachine.php on line 21
    }
  
  }
  ?&gt;
  &lt;html&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The error Messages are added as comments within the code. Tried alot of variants, mostly from Tutorials and other ressources, nothing worked so far, hence a little out of ideas where to look at the moment. What am i getting wrong here?</p>
  
  <p>edit:
  Some of the code in its correct form:</p>
  
  <pre><code>  public function __construct ($target_dir, $target_file)
    {
      $this-&gt;imageFile = $target_file;
      $this-&gt;imageExtension= pathinfo($target_file,PATHINFO_EXTENSION);
    }
  
    function saysth (){
      echo ($this-&gt;imageFile);
      echo "blah";
  
      switch ($this-&gt;imageExtension) {
        case 'jpg':
        case 'jpeg':
  </code></pre>