Re: Static weirdness..

From: Date: Thu, 19 Feb 2004 09:40:04 +0000
Subject: Re: Static weirdness..
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-7986@lists.php.net to get a copy of this message
== Quote from Greg Beaver (greg@chiaraquartet.net)'s article > <?php > class foo { > static function bar() > { > echo 'hello'; > } > } > > $bar = 'hello'; > $a = new foo; > $a->bar(); // this could be disabled to error out easily > $a::bar(); // my patch now allows this to print "hello" > $a::$bar(); // this also works > $a::{'bar'}(); // even this works > ?> The idea is good, but the syntax "$a::bar()" seems to me that $a is the name of the class, not an instance. I would prefer that PHP supports: $class = get_class($a); $class::bar(); or, to make it shorter: get_class($a)::bar(); Anyway, if you need to call a class method, but you only know an instance of it, this is certainly because the class was not properly defined. A class method is a method that applies to the class, not instances. And a method that does not need to use $this is not necessarily a class method. Stephane

« previous php.internals (#7986) next »