$this-> ? => ?
Moderator: General Moderators
$this-> ? => ?
Can somebody tell me what are -> and => , and their differences ? I've seen many usage of $this->(something). -> means some kinda pointer? One more thing, what is the scope of "this" keyword in php ? Is the scope same as in Java and C# ? I have been reading a bit of tutorial on Zend framework and several tutorial use the keyword "this" a lot and I have a pretty blur idea of how it's being used. Thanks all and will be looking forward to any input. Please if possible, provide some examples and I'd be really appreciated.
Last edited by Weirdan on Mon Mar 01, 2010 11:44 am, edited 1 time in total.
Reason: fixed title
Reason: fixed title
Re: Hi
-> is a member access operator - that is, you use it to access member variables (properties) of an object. => is invalid syntax - did you mean >= ? Edit: Of course => is a valid syntax for array definition and looping - stupid me. >= is a logical operator meaning 'greater or equal'.
$this is a special variable when used in a class context - it references current instance of the class, 'this object' to put it differently. Thus $this->id when called from a method would reference 'id' property of the object the method is called on.
As a side note, you'd better give your threads more descriptive names, 'Hi' is not really descriptive. It's also recommended by the forum rules to clearly name your threads - and a moderator may treat it as a requirement.
$this is a special variable when used in a class context - it references current instance of the class, 'this object' to put it differently. Thus $this->id when called from a method would reference 'id' property of the object the method is called on.
As a side note, you'd better give your threads more descriptive names, 'Hi' is not really descriptive. It's also recommended by the forum rules to clearly name your threads - and a moderator may treat it as a requirement.
Re: Hi
As Weirdan said -> is the member access operator.
=> is used to create and manipulate arrays - I'm not aware of any other uses but I may missing something.
Should output:
Cheers,
Dave.
=> is used to create and manipulate arrays - I'm not aware of any other uses but I may missing something.
Code: Select all
$my_array=array(
"first_key" => "some_value",
"second_key" => "another_value" );
foreach($my_array as $key => $value)
{
echo $key." = ".$value."<br />";
}Code: Select all
first_key = some_value
second_key = another_valueDave.
Re: Hi
Oh I'm sorry. I was in a big rush and didn't realize that I put "Hi" as this topic thread. My apology and thanks for the explanation too. One more thing, can you direct me to any good tutorial on php zend framework. For my project, I have to pick up php and this zend framework in a short time and I have a hard time understanding entire thing about zend framework. I tried following a few tutorial on zend framework and most of the time the zf script failed to do as expected as in tutorials. Is there any such way that I could create entire zend framework from scratch manually without using that zf script ? and if so how and which website to use as a reference ? Please help me out of this
. Thanks a lot