note 94606 added to language.oop5.static

From: Date: Fri, 13 Nov 2009 20:24:52 +0000
Subject: note 94606 added to language.oop5.static
Groups: php.notes 
Request: Send a blank email to php-notes+get-162881@lists.php.net to get a copy of this message
When a method is declared as static, not only is the magic variable $this unavailable (returns NULL), but it is impossible to tell if the function was actually called from a static context. A backtrace implies that for a static method, calling $object->method() is internally translated to className::method() at run time. <?php class Foo { static function bar() { var_dump(reset(debug_backtrace())); } } $foo = new Foo(); $foo->baz(); Foo::baz(); // Output in either case resembles this: // array(3) // { // 'file' => ..... // 'line => ..... // 'function' => string(3) 'baz' // 'class' => string(3) 'Foo' // 'type' => string(2) '::' // } ?> ---- Server IP: 64.71.164.2 Probable Submitter: 67.237.238.105 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.static.php Edit -- https://master.php.net/note/edit/94606 Del: integrated -- https://master.php.net/note/delete/94606/integrated Del: useless -- https://master.php.net/note/delete/94606/useless Del: bad code -- https://master.php.net/note/delete/94606/bad+code Del: spam -- https://master.php.net/note/delete/94606/spam Del: non-english -- https://master.php.net/note/delete/94606/non-english Del: in docs -- https://master.php.net/note/delete/94606/in+docs Del: other reasons-- https://master.php.net/note/delete/94606 Reject -- https://master.php.net/note/reject/94606 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#162881) next »