note 73306 added to language.oop5.static

From: Date: Fri, 16 Feb 2007 22:24:07 +0000
Subject: note 73306 added to language.oop5.static
Groups: php.notes 
Request: Send a blank email to php-notes+get-123498@lists.php.net to get a copy of this message
because when you call a method statically, outside of the class, you cannot access $this, not even indirectly: <?php class c { static $v = 'value'; function get_v() { return self::$v; } function get2() { return $this->v; } function doit() { echo 'self is ' . self::get_v() . '<br>'; echo 'this is ' . $this->get_v() . '<br>'; } } $o = new c; echo '<br><b>non-static func:</b><br>'; $o->doit(); echo '<br><b>static func:</b><br>'; c::doit(); ?> gives this: non-static func: self is value this is value static func: self is value Fatal error: Using $this when not in object context in [...] ---- Server IP: 69.147.83.197 Probable Submitter: 86.105.78.29 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.static.php Edit -- https://master.php.net/note/edit/73306 Del: integrated -- https://master.php.net/note/delete/73306/integrated Del: useless -- https://master.php.net/note/delete/73306/useless Del: bad code -- https://master.php.net/note/delete/73306/bad+code Del: spam -- https://master.php.net/note/delete/73306/spam Del: non-english -- https://master.php.net/note/delete/73306/non-english Del: in docs -- https://master.php.net/note/delete/73306/in+docs Del: other reasons-- https://master.php.net/note/delete/73306 Reject -- https://master.php.net/note/reject/73306 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#123498) next »