electroteque wrote:

On 29/01/2005, at 12:02 AM, Jochem Maas wrote:



classes cannot be defined as static - defining them as abstract has the effect
of being able to only use a given class statically (unless you subclass it and the subclass
is not abstract).



abstract as in it is the final base class ?


no abstract as in 'cannot be instantiated' try running the following:

abstract class MyClass
{
        public function __construct()
        {
                echo "boo!";
        }
}

$mc = new MyClass;

the 'final' keyword is used to declare that a class or method cannot be
overridden by (or in) a subclass.


variables inside it, or its only meant to stay in the one static method so


yes you can use variables - but not member variables because $this is not defined in functions
that are declared static - bare in mind you can call a method statically even though its not
marked as static (just be sure you don't reference $this).


i meant member vars , what is the point of static methods anyway ?

difficult question. a start would be to say that static methods offer a neat way to organise your code (sort of cheapmans namespace).

PHP5 also offers static class vars:

abstract class MyClass
{
        static private $val;

        static public function set($v)
        {
                self::$val = $v;
        }

        static public function speak()
        {
                if (!is_null(self::$val)) {
                        echo self::$val."\n";
                } else {
                        echo "<silence>\n";
                }
        }
}

MyClass::set("yeah");
MyClass::speak();




sidenote: the php4 trick of overwriting $this does not work in PHP5.




that i cant live with


good ;-) ... the reason it doesn't work is the same reason PHP5 objects are soooo much cooler, namely a rewritten object model. thank the gods!

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



Reply via email to