note 68304 added to language.variables.scope

From: Date: Fri, 21 Jul 2006 16:18:46 +0000
Subject: note 68304 added to language.variables.scope
Groups: php.notes 
Request: Send a blank email to php-notes+get-115015@lists.php.net to get a copy of this message
PHP 5.1.4 doesn't seem to care about the static keyword. It doesn't let you use $this in a static method, but you can call class methods through an instance of the class using regular -> notation. You can also call instance methods as class methods through the class itself. The documentiation here is plain wrong. class Foo { public static function static_fun() { return "This is a class method!\n"; } public function not_static_fun() { return "This is an instance method!\n"; } } echo '<pre>'; echo "From Foo:\n"; echo Foo::static_fun(); echo Foo::not_static_fun(); echo "\n"; echo "From \$foo = new Foo():\n"; $foo = new Foo(); echo $foo->static_fun(); echo $foo->not_static_fun(); echo '</pre>'; You'll see the following output: From Foo: This is a class method! This is an instance method! From $foo = new Foo(): This is a class method! This is an instance method! ---- Server IP: 217.13.201.10 Probable Submitter: 217.111.5.124 ---- X-Spam-Status: No, hits=3.3 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER, HTML_MESSAGE autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/language.variables.scope.php Edit -- http://master.php.net/note/edit/68304 Del: integrated -- http://master.php.net/note/delete/68304/integrated Del: useless -- http://master.php.net/note/delete/68304/useless Del: bad code -- http://master.php.net/note/delete/68304/bad+code Del: spam -- http://master.php.net/note/delete/68304/spam Del: non-english -- http://master.php.net/note/delete/68304/non-english Del: in docs -- http://master.php.net/note/delete/68304/in+docs Del: other reasons-- http://master.php.net/note/delete/68304 Reject -- http://master.php.net/note/reject/68304 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#115015) next »