Reputation: 4094
I'm looking at some code here and there are bunch of calls that are like this. I don't have much experience with php, mainly java. Is this like if I had a Dog object that had a fur object and I wanted to call "dog.getFur().getColor();" ?
Example:
$this->tbtemp_list1->lead_time = ($this->add_lead_time->Text + $this->add_transit_time->Text);
$this->tbtemp_list1->units = $this->add_units->Text;
$this->tbtemp_list1->item_class = $this->txtClass->Value;
$this->tbtemp_list1->category = $this->add_part_category->Text;
$this->tbtemp_list1->description = $this->add_part_description->Text;
$this->tbtemp_list1->notes = $this->txtNotes->Text;
Upvotes: 0
Views: 71
Reputation: 72971
->
(arrow) is object notation in PHP.
It's equivalent is the .
(dot) object notation Java.
For example:
// PHP
$this->tbtemp_list1->lead_time
is:
// Java
this.tbtemp_list1.lead_time
In this case, you are reference a property (lead_time
) that is a property of an object lead_time
which is a property of an object ($this
). This can go on forever provided the property is an object.
Upvotes: 1
Reputation: 17574
Is this like if I had a Dog object that had a fur object and I wanted to call "dog.getFur().getColor();" ?
Yes. The "->" operator in PHP is similar to the "->" operator in C.
In C, it gets a member from a pointer. In PHP, it gets a member from a reference. Since PHP is written in C, I suspect that the syntax for accessing members from objects was directly borrowed from C.
Edit:
It's also good to note here that static members require a different syntax.
print className::$staticVariable;
Upvotes: 1
Reputation: 32532
in php
a->b->c is accessing c which is a property or method of b, and b is a child object of a. In javascript, you're just method chaining.
Upvotes: 2
Reputation: 1374
You are right in your thinking, the -> operator simply accesses a member of an object, such that in $this->tbtemp_list1->lead_time
the tbtemp_list1 member of the current object is being accessed, and then the lead_time member of the tbtemp_list1 member.
Upvotes: 2