Jump to content


public static


2 replies to this topic

#1 dEcade

    P2L Staff

  • P2L Staff
  • PipPipPipPip
  • 1,850 posts
  • Gender:Male
  • Location:Saskatoon, Saskatchewan
  • Interests:Guitar, Programming, Storm Chasing, Games (Designing and playing), Hockey, Photography

Posted 30 November 2006 - 08:18 PM

Hi, well I am starting to write a php framework script and I was looking at one for ideas on what else to add and I noticed they did something like this:

class NAME
{
	public static function_name($stuff)
	{
		self::fail();
	}

	public static function fail()
	{
		$something	=	'fail';
		return fail;
	}
}

OK first what is the public static used for and why do they do self::fail(); instead of something like $this->fail();

dEcade

#2 dEcade

    P2L Staff

  • P2L Staff
  • PipPipPipPip
  • 1,850 posts
  • Gender:Male
  • Location:Saskatoon, Saskatchewan
  • Interests:Guitar, Programming, Storm Chasing, Games (Designing and playing), Hockey, Photography

Posted 30 November 2006 - 08:39 PM

I think I got it, public static means that the class doesn't have to be defined and the use of :: replaces -> because the class is not defined.

dEcade

#3 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 30 November 2006 - 09:33 PM

Exactly. :D

Using the 'self::' instead of '->' allows for the class to run annoynomous, so you can use the 'Class::' syntax and not have to initiate a new class. :)
Took me awhile when I was first looking through going 'what the hell is :: for?'. Lol.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users