note 68477 added to keyword.paamayim-nekudotayim
| From: | docey at osu1 dot php dot net | Date: | Fri, 28 Jul 2006 18:38:36 +0000 |
| Subject: | note 68477 added to keyword.paamayim-nekudotayim | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-115303@lists.php.net to get a copy of this message | ||
after doing some research as the manual was somewhat
vague, i found out that using $this in a class-function is
not fatal as the manual implied, its not even a warning.
it simply comes with a notice saying: $this is undefined.
it appears the class-function is just as a global function.
and as such the static keyword holds its value after scope
changes.
however it seems to also holds its value after the class
gets instanced. take a simple counter function thats a
member of a class. make a few calls to the counter to
let it count to lets say 3. then instance the class and let
it count it again 3 times. you think the score is now 3,
infact its 6.
so one simple way to find out if a function is called from
a instanced class or not is to have the constructor set a
class variable and then check for it using isset. since in
the class-function scope the $this is unavailable isset
will return false. but when the class has been instanced
it will return true.
btw, i tested it with php4.4.2CLI.
hope this will clear somethings up.
----
Server IP: 83.137.20.120
Probable Submitter: 82.75.98.252
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/keyword.paamayim-nekudotayim.php
Edit -- http://master.php.net/note/edit/68477
Del: integrated -- http://master.php.net/note/delete/68477/integrated
Del: useless -- http://master.php.net/note/delete/68477/useless
Del: bad code -- http://master.php.net/note/delete/68477/bad+code
Del: spam -- http://master.php.net/note/delete/68477/spam
Del: non-english -- http://master.php.net/note/delete/68477/non-english
Del: in docs -- http://master.php.net/note/delete/68477/in+docs
Del: other reasons-- http://master.php.net/note/delete/68477
Reject -- http://master.php.net/note/reject/68477
Search -- http://master.php.net/manage/user-notes.php