Why can I call a non-stationary function without declaring a class object?

I am using Symfony 1.0 and I have this MyClassInc.class.phpin my folderproject/lib

class MyClassInc {
  public function validateFunction ($params) {
    // my codes
  }
  static function testFunction ($params){
    // my codes
  }
}

Then my action is actions.class.phpin mine project/apps/myapps/modules/actions.

class inventoryCycleCountActions extends sfActions
{
  public function validateOutstandingTransaction () {
    $res0 = MyClassInc :: validateFunction($param); // It works
    $res1 = MyClassInc :: testFunction($param); // It works
    $myClass = new MyClassInc();
    $res2 = $myClass->validateFunction($param); // still works
    $res3 = $myClass->testFunction($param); // still works, da hell?
  }
}

I tried to clear the cache folder in order to re-check, but it seems that they all work fine.

Question: So ... WHY? and which should i use? Does this have any effect on performance or something else?

Update 1:

class MyClassInc {
  public function isProductValidated ($product){
    return true;
  }
  public function validateFunction ($params) {
    // IF, I call by using "$res0".. Throws error
    //
    $this->isProductInLoadPlans($product);
  }
}

If I call validateFunction using $ res0 , it will raise this error:

sfException: method call undefinedinventoryCycleCountActions :: isProductValidated.

And , if I call it through $ res2 , it works fine.

$res0, .

MyClassInc:: isProductValidated ($ product)

+4
1

:: -> , $this. :: $this, :

class A {

  public function foo() {
    A::bar();
    A::foobar();
  }

  static private function bar() {
     // $this here is the instance of A
  }

  static public function foobar() {
    // Here you can have anything in $this (including NULL)
  }
}

$a = new A;
$a->foo();
$a->foobar(); // $this == $a but bad style
A::foobar(); // $this == NULL

, ->, ( ). :: .

, , , .

0

All Articles