note 114647 added to language.oop5.static
| From: | DenisRibeiro-dpr001 at gmail dot com | Date: | Sun, 16 Mar 2014 14:23:57 +0000 |
| Subject: | note 114647 added to language.oop5.static | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-198906@lists.php.net to get a copy of this message | ||
Other point is that static methods just can access static properties, because the pseudo variable
$this not exists in this scope like example below:
<?php
//is wrong, because the static methods can only access static properties
class Foo {
public $property;
public static function aStaticMethod() {
echo "Accessing the property: {$this->property}"; //Fatal error:Using $this
}
}
Foo::aStaticMethod();
$classname = 'Foo';
$classname::aStaticMethod(); // As of PHP 5.3.0
//Note that property $property is static and then can be using the word self instead of pseudo
variable $this
class Foo2 {
static $property = 'test';
public static function aStaticMethod() {
echo "Accessing the property: ". self::$property; //Accessing the property: test
}
}
Foo2::aStaticMethod();
----
Server IP: 72.52.91.14
Probable Submitter: 177.80.142.147
----
Manual Page -- http://php.net/manual/en/language.oop5.static.php
Edit -- https://master.php.net/note/edit/114647
Del: integrated -- https://master.php.net/note/delete/114647/integrated
Del: useless -- https://master.php.net/note/delete/114647/useless
Del: bad code -- https://master.php.net/note/delete/114647/bad+code
Del: spam -- https://master.php.net/note/delete/114647/spam
Del: non-english -- https://master.php.net/note/delete/114647/non-english
Del: in docs -- https://master.php.net/note/delete/114647/in+docs
Del: other reasons-- https://master.php.net/note/delete/114647
Reject -- https://master.php.net/note/reject/114647
Search -- https://master.php.net/manage/user-notes.php