title: Laravel4, access instance methods within a Facade implementation ends up in PHP fatal: call to undefined method
body: <p>This is a test i am running to understand how framework works. I've coded a trivial facade implementation, a service provider and i properly registered it. Code:</p>
  
  <pre><code>// This is the facade 
  &lt;?php
  namespace my\facades;
  use Illuminate\Support\Facades\Facade;
  
  class DateHelper extends Facade {
      /**
       *  Get the registered name of the component.
       *  @return string
       */
      protected static function getFacadeAccessor() { 
          // Return the instance key name in the IoC Container.
          return 'my.utils.dateHelper'; 
      }
  
  }
  
  // This is the service provider
  &lt;?php
  namespace my\providers;
  class MyServiceProvider extends \Illuminate\Support\ServiceProvider {
      /**
       *  Register the service provider.
       */
      public function register() {
  
      // Register the date handler
      $this-&gt;app['my.utils.dateHelper'] = $this-&gt;app-&gt;share(function($app) {
              return new \my\utils\DateHelper();
      });
  
  
  
          // Shortcut so developers don't need to add an Alias in app/config/app.php
          $this-&gt;app-&gt;booting(function(){
              $loader = \Illuminate\Foundation\AliasLoader::getInstance();
  
              $loader-&gt;alias('DateHelper', '\my\utils\DateHelper');
  
          });
      }
  }
  // This is the actual implementation
  class DateHelper {
      public static $UI_DATE_FORMAT = 'd/m/y';
      public static $UI_DATETIME_FORMAT = 'd/m/y H:i:s';
  
      /**
       * 
       *  Enter description here ...
       *  @param DateTime $date0
       *  @param DateTime $date1
       */
      public function compare(mixed $date0, mixed $date1) {
          if (is_string($date0)) {
              $date0 = $this-&gt;a($date0)-&gt;getTimestamp();
          }
          if (is_string($date1)) {
              $date1 = $this-&gt;a($date1)-&gt;getTimestamp();
          }
          return $date0 &lt; $date1 ? -1 : $date1 &gt; $date0 ? 1 : 0;
      }
  
      /**
       * 
       *  Enter description here ...
       *  @param string $inputDate
       */
      public function a( $inputDate) {
          return \DateTime::createFromFormat(self::$UI_DATE_FORMAT, $inputDate);
      }
  }
  </code></pre>
  
  <p>Now, i.e. from a Controller, i am able to</p>
  
  <ul>
  <li>invoke DateHelper::compare("one", "two");</li>
  <li>invoke DateHelper::a(1);</li>
  </ul>
  
  <p>Methods are properly resolved. What is not working is the line of the sort</p>
  
  <pre><code>$date0 = $this-&gt;a($date0)-&gt;getTimestamp();
  </code></pre>
  
  <p>where i get a PHP fatal stating that</p>
  
  <pre><code>PHP Fatal error:  Call to undefined method DateHelperTest::a()
  </code></pre>
  
  <p>I think this has something to do with magic methods. I tried to invoke them
  statically, but nothing changes. How i can i invoke </p>
  
  <blockquote>
    <p>a()</p>
  </blockquote>
  
  <p>from the </p>
  
  <blockquote>
    <p>compare()</p>
  </blockquote>
  
  <p>body?</p>
  
  <p><strong>== EDIT ==</strong></p>
  
  <p>I am writing a test against this facade, the like of this</p>
  
  <pre><code>&lt;?php
  class DateHelperTest extends \TestCase {
  
      public function testComparison() {
          // Compare strings
          $d0 = "01/01/2012";
          $d1 = "02/01/2012";
          $this-&gt;assertEquals(DateHelper::compare($d0, $d1), 1);
          $this-&gt;assertEquals(DateHelper::compare($d1, $d0), -1);
          $this-&gt;assertEquals(DateHelper::compare($d0, $d0), 0);
  
          // Compare DateTimes
          $dateTime0 = new DateTime($d0);
          $dateTime1 = new DateTime($d1);
          $this-&gt;assertEquals(DateHelper::compare($dateTime0, $dateTime1), 1);
          $this-&gt;assertEquals(DateHelper::compare($dateTime1, $$dateTime0), -1);
          $this-&gt;assertEquals(DateHelper::compare($dateTime0, $dateTime1), 0);
    }
  
    public function testParser() {
      $sample = "01/02/2012";
      $d = DateHelper::parseInput($sample);
      $this-&gt;assertEquals($d-&gt;format("d/m/Y"), $sample);
      $this-&gt;assertEquals($d-&gt;format("d"), "01");
      $this-&gt;assertEquals($d-&gt;format("m"), "02");
      $this-&gt;assertEquals($d-&gt;format("Y"), "2012");
    }
  
  }
  </code></pre>
  
  <p>I just spotted a weird thing i didn't see at first. Error states that</p>
  
  <blockquote>
    <p>PHP Fatal error:  Call to undefined method
    DateHelperTest::parseInput() in
    /var/www/my/app/my/utils/DateHelper.php on line 15</p>
  </blockquote>
  
  <p>so, what's this? the $this->fooBar method in DateHelper is resolved to DateHelperTest->foobar()?</p>