Re: Re: self:: vs this

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

 



M.Sokolewicz wrote:
Basically what you can remember here is:
:: calls a property or method in a STATIC context (ie. without access to the object's (if any) actual properties) -> calls a propert or method in a DYNAMIC context (ie. WITH access to that specific object's collection of methods and properties).


While that's generally true, self::, parent::, ClassName:: and ParentClassName:: can all be used in both contexts when calling methods.

Consider the following code:

<?php
class Foo {
   function bar() { var_dump(isset($this)); }
}
class Test extends Foo {
   function __construct()
   {
       self::bar();
       parent::bar();
       Foo::bar();
       Test::bar();
   }
}
new Test;
?>

At first glance these all appear to be static method calls, but $this is available in every case.

Arpad

--
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