TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   Just a quick question.... (http://www.talkphp.com/absolute-beginners/3259-just-quick-question.html)

frosty 08-19-2008 02:15 PM

Just a quick question....
 
Hi, for those of you that have checked my introduction post, you will know that I am an Art Director that just knows a bit of programming...

While I might know some I do not speak the programmers terms/language...is there a good reference that anyone can point me to where I can get terms in regular English...

For example:

I know when I might need to do something like
PHP Code:

$this -> and_stuff_here

But I have no idea what "$this" actually is called or why I really need it, but I know I need to use it when I use it...(did that make any sense at all)

Thanks.

***EDIT***

NM I found the glossary…this may answer a lot of my questions…

Thanks

adamsargant 08-19-2008 06:23 PM

"$this" is a pseudo variable used within a class to refer to the class itself. Obviously, since the object hasn't been instantiated yet, we can't use it within the class.

say I have an object $foo

$foo=new myclass();

and a property $bar, I can now call that property

$foo->bar

BUT, within the class code, I don't know I'm going to call the object "$foo", so "$this" is used as a generic reference to the object

I'm just getting my head round classes myself, so I hope that helps :-)

Adam

frosty 08-19-2008 07:16 PM

Adam,

Thanks for the reply...$this was not in the Glossary.

So it makes better sense now.

Like I said, I know when, but not the whys or what fors of most of this...haha

So now how do I close this Thread?

Kalle 08-19-2008 08:32 PM

It might also be worth to notice that $this is a reserved keyword and cannot be overridden when called inside a method.

$this is only available when a method is called from an intialized object, and not staticlly calls, eg. this wouldn't work:

PHP Code:

<?php
    
class TalkPHP
    
{
        protected 
$name;


        public static function 
who($name)
        {
            
$this->name $name;
        }
    }

    
TalkPHP::who('Kalle');
?>

Hope this helps you abit further ;)

frosty 08-19-2008 09:05 PM

Yes it does! Thank you!


All times are GMT. The time now is 02:20 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0