note 80623 deleted from language.oop5.static by felipe

From: Date: Sat, 09 Feb 2008 16:58:29 +0000
Subject: note 80623 deleted from language.oop5.static by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-135931@lists.php.net to get a copy of this message
Note Submitter: Luke Ashe-Browne ---- The method works fine, if you are on the correct version of PHP. As of 5.3.0 you can refer to a static class from a variable name as shown. <?php $classname='Foo'; $classname::aStaticMethod(); ?> Prior to this you will receive an error "Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM" on calling $classname::aStaticMethod(). I have tested this works on PHP 5.3.0 and that it fails with the above error on 5.2.3 and 5.1.2. What does work at the above pre 5.3.0 versions is basic accessors to static methods as shown below. <?php class Foo{ public static function aStaticMethod(){ echo "static \n"; } } Foo::aStaticMethod(); ?> I can't tell what version they started at though, as I don't have any earlier installations other than PHP 4.3.9 which doesn't even recognise the static keyword in the method definition. I hope this helps anyone confused by what should and shouldn't work at different version.

« previous php.notes (#135931) next »