List Info

Thread: note 68477 added to keyword.paamayim-nekudotayim




note 68477 added to keyword.paamayim-nekudotayim
user name
2006-07-28 18:38:36
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-nekud
otayim.php
Edit        -- http://master.p
hp.net/note/edit/68477
Del: integrated  -- ht
tp://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://m
aster.php.net/note/delete/68477/spam
Del: non-english -- h
ttp://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://ma
ster.php.net/manage/user-notes.php

-- 
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php

[1]

about | contact  Other archives ( Real Estate discussion Medical topics )