Jump to content

OO with PHP 5 question


hvle

Recommended Posts

You need a visibility operator in front of 'static', like 'public' or 'private'.  Also are you declaring that variable outside a class? As far as I know, static variables are restricted to classes, though I miay be wrong.

Check out [url=http://uk.php.net/manual/en/language.oop5.static.php]static keyword[/url] at PHP.net
Isn't that fatally recursive?

If you're just looking for a static class that you don't have to instantiate, declare the members of a standard class 'static' and then access them with the :: operator, like this (from the above linked page)...

[code]
class Foo
{
  public static $my_static = 'foo';
  .
  .
  .
}

print Foo::$my_static . "\n";
[/code]

Is that what you're after?
[quote author=Jenk link=topic=114130.msg464240#msg464240 date=1162908769]
it would have to be:
[code]<?php
class MyClass
{
  private static $my_instance;

  function getInstance()
  {
      self::$my_instance = new MyClass();
  }
}
?>[/code]
[/quote]

whoops my bad. cheers ;)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.