• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A fairly dumb question...

#2
[eluser]Hyra[/eluser]
The main difference, if not the only one, is that you use the double colon for static members, and the arrow for members


Static Member
Code:
class Foo
{
   public static $my_static = 'foo';

   public function staticValue() {
       return self::$my_static;
   }
}

class Bar extends Foo
{
   public function fooStatic() {
       return parent::$my_static;
   }
}


print Foo::$my_static . "\n";

$foo = new Foo();
print $foo->staticValue() . "\n";
print $foo->my_static . "\n";      // Undefined "Property" my_static

// $foo::my_static is not possible

print Bar::$my_static . "\n";
$bar = new Bar();
print $bar->fooStatic() . "\n";

Static method
Code:
class Foo {
   public static function aStaticMethod() {
       // ...
   }
}

Foo::aStaticMethod();

So .. :: can only be used for static (non-changing) methods/members


Messages In This Thread
A fairly dumb question... - by El Forum - 03-03-2008, 08:58 AM
A fairly dumb question... - by El Forum - 03-03-2008, 09:11 AM
A fairly dumb question... - by El Forum - 03-03-2008, 09:16 AM
A fairly dumb question... - by El Forum - 03-03-2008, 12:10 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.