The very basics in simple language:

An object is grouping variables and functions together.

class MyObject {
        var $myObjectVariable = 12;

        function myObjectFunction() {
                // does something
        }
}

You can move a bunch of functions and variables around in one package  
without worrying about naming conflicts with other variables or  
function names, and can reliably access those variables inside the  
object since they're guaranteed to be packaged together.

$obj = new MyObject();

Now $obj has all the stuff I declared above in "class MyObject". To  
access all that stuff, you use ->.

$obj->myObjectVariable;         // = 12
$obj->myObjectFunction();       // does something

The question that remains is, how do you access $obj->myObjectVariable  
from within the object itself (i.e. from the line "// does something"  
above)? The answer: $this.

class MyObject {
        var $myObjectVariable = 12;

        function myObjectFunction() {
                $this->myObjectVariable;        // refers to 12 above
        }
}

Just felt like posting that here... ;)


On 6 Oct 2008, at 12:19, mattocrocop wrote:

>
> Cool.  Thanks guys!  My problem with searching for the answers was
> really that I didn't know what I was looking for.  I wasn't sure
> whether it was a feature of basic PHP, OOP, or CakePHP.  I guess that
> the last time I looked at PHP in any detail was probably prior to PHP
> 5.
>
> Once again, thanks to everyone for your support.
>
> On Oct 5, 11:06 pm, Dave Porter <[EMAIL PROTECTED]> wrote:
>> I too have battled with this, so went hunting....
>>
>> I found this explanation that I think is fairly clear!
>>
>>>>>>>>>>>>>>>>  $this explanation
>>
>> The $this pseudo-variable provides a mechanism for objects to refer  
>> to
>> their own properties and methods. Outside of an object, there is a
>> handle you can use to access its elements.
>> Inside an object, there is no such handle, so you must fall back on
>> $this. If you find $this confusing, try replacing it in your mind  
>> with
>> the current instance when you encounter it in code.
>> <<<<<<<<<<<<<<<<  End
>>
>>>>>>>>>>>>>>>>  -> explanation
>>
>> You can access public object properties using the object operator '- 
>> >'. So $en->type means the $type property of the Dictionary object
>>
>> referenced by $en. If you can access a property, it means that you  
>> can
>> set and get its value.
>> <<<<<<<<<<<<<<<<< End
>>
>> HTH - Dave Porter
>>
>> On Oct 6, 9:29 am, "Gonzalo Servat" <[EMAIL PROTECTED]> wrote:
>>
>>> On Sun, Oct 5, 2008 at 10:38 PM, mattocrocop  
>>> <[EMAIL PROTECTED]> wrote:
>>
>>>> Thanks to all the guys who offered help.  I found this great video
>>>> series for beginners to OOP.
>>
>>>> http://www.killerphp.com/tutorials/object-oriented-php/index.php
>>
>>>> The last minute or so of Build Objects in PHP - Part I and the  
>>>> bulk of
>>>> Part II offer a decent enough description of the meaning of  
>>>> "$this",
>>>> and the of "->".
>>
>>> Thanks Matt for writing back. I'm sure beginners to OOP will  
>>> appreciate the
>>> link.
>>
>>> - Gonzalo
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to