Re: context when calling non static method of class in a static way

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



class A {
    public function b() {
        echo get_class($this);
    }
    static function c() {
        echo get_class($this);
    }
}

class B {
    public function test(){
        A::b();
        A::c();
    }
}
$b = new B;
$b->test();

Generates:
Strict Standards: Non-static method A::b() should not be called
statically, assuming $this from incompatible context in /tmp/test.php
on line 14
B
Notice: Undefined variable: this in /tmp/test.php on line 8
A

I would never use code generating warnings and notices like that. I'd
look into late static bindings instead:
http://php.net/manual/en/language.oop5.late-static-bindings.php

Regards
Peter

-- 
<hype>
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
</hype>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux